views:

206

answers:

2

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!!

+1  A: 

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.

wallyk
@wallyk - +1 for the helpful tip. still not quite there, but that does put me in the right direction thanks! I can pass a file in now, but still can't figure out how to pass a string in.
jaywon
+1  A: 

I haven't gotten any more posts, but after toying with the system() function, I was able to redirect a file as input to STDIN but was unable to pass a string of data. I had the option of doing something similar to a batch job in my PHP where I would write a temp file, and use that as input to STDIN, but since I was already using a batch file for the post-commit hook in SVN to call the PHP script I figured I would go ahead and just write the entire script there in the batch file.

Here is my final solution for the SVN post-commit hook:

post-commit.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%

This script updates a matching mantis ticket with a comment in the following format:

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
jaywon