1

I have been following the post below trying to hook my SubVersion installation to my Mantis bug tracker.

How To Integrate Subversion and Mantis

Everything works fine until the last line where it calls the Mantis checkin.php script and feeds it the message string that has been created in the script.

exec(CHECKIN . " <<< \"$message\"");

I understand the purpose of the line is to send the message string to STDIN which Mantis' checkin.php reads in order to check for an appropriate matching string and update the Mantis tracking database.

Anyways, I know the above convention is for a Linux installation. My question is how would I use the PHP exec() function in a Windows environment to call the PHP script(checkin.php) and pass the string built in this program to STDIN.

NOTE: I would prefer not to change the logic in checkin.php to read from STDIN.

Thanks!!

4

2 回答 2

1

Redirects using the < and > are processed by the shell—on windows by cmd.exe. The easiest way to get that functionality is with system(). exec() does not use a shell: to use it, you'd have to orchestrate the redirection before calling exec.

于 2009-11-24T02:09:32.843 回答
1

我还没有收到更多帖子,但是在玩弄了 system() 函数之后,我能够将文件作为输入重定向到 STDIN,但无法传递数据字符串。我可以选择在我的 PHP 中执行类似于批处理作业的操作,我将在其中编写一个临时文件,并将其用作 STDIN 的输入,但由于我已经在 SVN 中使用批处理文件作为提交后挂钩来调用PHP 脚本我想我会继续在批处理文件中编写整个脚本。

这是我对 SVN 提交后挂钩的最终解决方案:

提交后.bat

@ECHO off
SETLOCAL

SET REPOS=%1
SET REV=%2

SET PHP="C:\Program Files\PHP\php.exe"
SET CHECKIN="D:\mantisbt-1.1.8\core\checkin.php"
SET SVNLOOK="C:\Program Files\CollabNet\Subversion Server\svnlook.exe"

SET LOGFILE=log%REV%.txt
SET AUTHORFILE=author%REV%.txt
SET OUTPUTFILE=output%REV%.txt
SET CHANGEFILE=change%REV%.txt

ECHO Author: > %AUTHORFILE%
%SVNLOOK% author -r %REV% %REPOS% >> %AUTHORFILE%

ECHO Log: > %LOGFILE%
%SVNLOOK% log -r %REV% %REPOS% >> %LOGFILE%

ECHO Files: > %CHANGEFILE%
%SVNLOOK% changed %REPOS% %REV% >> %CHANGEFILE%

ECHO Revision: %REV% > %OUTPUTFILE%
%SVNLOOK% date %REPOS% -r %REV% >>  %OUTPUTFILE%
TYPE %AUTHORFILE% >> %OUTPUTFILE%
TYPE %LOGFILE% >> %OUTPUTFILE%
TYPE %CHANGEFILE% >> %OUTPUTFILE%

TYPE %OUTPUTFILE% | %PHP% %CHECKIN% 

CALL DEL %LOGFILE%
CALL DEL %AUTHORFILE%
CALL DEL %CHANGEFILE%
CALL DEL %OUTPUTFILE%

此脚本使用以下格式的注释更新匹配的螳螂票:

Revision: 41
2009-11-25 11:47:18 -1000 (Wed, 25 Nov 2009)
Author: 
jason
Log: 
Testing for checkin for TER #12345 which fixes Mantis issue 0000001.
Files:
U TANDEM/CAB/CABLONGD
于 2009-12-01T19:37:06.367 回答