How to overcome batch file execution part way through when using CFExecute with PsExec to run Git actions?

StackOverflow https://stackoverflow.com/questions/14590552

문제

I’m encountering a weird issue and have tried many different things.

The goal is to have a user click a button on a web page that will execute a batch file on several other servers.

I am using ColdFusion 8. When the user clicks the button, CFExecute launches PSExec.exe to execute the file on remote machine.

excerpt from bat file

cd c:\web\www >> \\firstmachine\c$\web\qa\html\RA\ra.log
git pull origin master >> \\firstmachine\c$\web\qa\html\RA\ra.log

cd c:\web\aaa >> \\firstmachine\c$\web\qa\html\RA\ra.log
git pull origin master >> \\firstmachine\c$\web\qa\html\RA\ra.log

When I run it from a command prompt git runs properly and does a pull from www and aaa. Log file shows everything worked as expected.

c:\web\qa\html\RA\PsExec.exe \\othermachine -u domain\adminaccount -p <password> c:\web\qa\html\RA\script.bat

When I run the same command from CF using CFExecute, git only does a pull on www and not aaa.

<cfexecute name="c:\web\qa\html\RA\PsExec.exe" 
       variable="var" arguments="\\othermachine -u 
       domain\adminaccount -p <password> c:\web\qa\html\RA\script.bat" 
       timeout="50"> 
</cfexecute>

If I swap the lines around, git does a pull on aaa and not www. In these cases the log file shows nothing after the first successful pull, as if the process aborted, but I can not find anything else out of the ordinary.

Any thoughts are much appreciated!

도움이 되었습니까?

해결책 2

I ended up taking out the batch file and using a separate CFExecute command for each action.

다른 팁

You can try to use CALL command and have both blocks in separate labels. When you run batch file from outside programs, you need to specify exit /b [error_code]. What probably happens if batch executes first git pull and returns success code to what has called it. The structure below will only send it after it successfully executes both parts.

SET _err_lvl=0
CALL :pull_www
CALL :pull_aaa

IF %_err_lvl% EQU 0 exit /b 0

:pull_www
cd c:\web\www >> \\firstmachine\c$\web\qa\html\RA\ra.log
git pull origin master >> \\firstmachine\c$\web\qa\html\RA\ra.log
IF %ERRORLEVEL% NEQ 0 SET _err_lvl=1
:end_pull_www
GOTO: eof

:pull_aaa
cd c:\web\aaa >> \\firstmachine\c$\web\qa\html\RA\ra.log
git pull origin master >> \\firstmachine\c$\web\qa\html\RA\ra.log
IF %ERRORLEVEL% NEQ 0 SET _err_lvl=1
:end_pull_aaa
GOTO: eof
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top