0

我遇到了一个奇怪的问题,并尝试了许多不同的事情。

目标是让用户单击网页上的按钮,该按钮将在其他几个服务器上执行批处理文件。

我正在使用 ColdFusion 8。当用户单击按钮时,CFExecute 启动 PSExec.exe 以在远程计算机上执行文件。

bat文件的摘录

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

当我从命令提示符运行它时,git 会正常运行并从 www 和 aaa 拉取。日志文件显示一切都按预期工作。

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

当我使用 CFExecute 从 CF 运行相同的命令时,git 只会拉 www 而不是 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>

如果我换行,git 会拉动 aaa 而不是 www。在这些情况下,第一次成功拉取后,日志文件什么也没有显示,就好像进程中止了一样,但我找不到任何其他异常。

任何想法都非常感谢!

4

2 回答 2

1

您可以尝试使用 CALL 命令并将两个块放在不同的标签中。当您从外部程序运行批处理文件时,您需要指定 exit /b [error_code]。如果批处理首先执行 git pull 并将成功代码返回给调用它的对象,可能会发生什么情况。下面的结构只有在成功执行这两个部分后才会发送它。

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
于 2013-02-15T19:20:53.803 回答
0

我最终取出批处理文件并为每个操作使用单独的 CFExecute 命令。

于 2017-07-18T22:10:56.047 回答