问题
I have a slow running batch file that compiles a log of changes and then emails a user. I would like it not to cause the user's commits to perform slowly in TortoiseSVN.
@ECHO OFF
SET REPOS=%1
SET REV=%2
SET DIR=%REPOS%/hooks
SET PATH=%PATH%;%DIR%;C:\Utils
SET WORKING_COPY=C:\path\to\local\copy\
SET SITENAME=MySiteName
SET SMTP_SERVER=11.11.11.11
SET EMAIL_TO=my@email.email
SET EMAIL_FROM=my@email.email
SET SUBJECT=SVN Update - %SITENAME% - rev %REV% - %REPOS%
svn cleanup %WORKING_COPY%
svn update %WORKING_COPY%
ECHO The following changes were made to the code: > %DIR%/email.txt
ECHO. >> %DIR%/email.txt
svn log %WORKING_COPY% -v -r "%REV%" >> %DIR%/email.txt
svn diff %WORKING_COPY% -c "%REV%" --no-diff-deleted >> %DIR%/email.txt
sendEmail -s %SMTP_SERVER% -t %EMAIL_TO% -f %EMAIL_FROM% -u "%SUBJECT%" -o message-file=%DIR%/email.txt
I realised that this was running slowly, so I moved it to another file "email-changes.bat" and created a simple batch to call this batch asynchronously.
@ECHO OFF
#START %1\hooks\email-changes.bat %1 %2
echo 'fired' > %1\hooks\test.log
If I comment out the "START" line it runs and finishes instantly. If I remove the comment it takes forever to complete. I thought that should allow the post-commit to return to SVN quickly.
Is there any way I can get the code to not hang in Subversion, but still complete the emailing task in the background?
回答1:
Try starting the real hook script in a separate process:
@ECHO OFF
cmd.exe /c START %1\hooks\email-changes.bat %1 %2
echo 'fired' > %1\hooks\test.log
if that doesn't work, find a tool that can start another bat file in a separate process/thread.
来源:https://stackoverflow.com/questions/5819742/how-do-i-run-a-slow-running-batch-asynchronously-specifically-a-svn-post-commit