我正在编写几个PHP脚本来执行一个程序,捕获它的STDOUT并在完成时捕获返回代码。 这些程序可以立即返回,或者在20分钟内完成,所以我需要监视什么时候完成。
我找不到在后台启动程序的方法,并将返回代码捕获到[外部日志文件]。 如果我只是简单的使用exec或者proc_open,我的PHP脚本就会被阻塞,当这个过程需要20分钟时,这是不好的。
即使我无法获取返回码,我也需要知道该过程何时完成。 (我可以把错误代码放在STDOUT中)
我可以使用exec("start my.exe"); 并抓住STDOUT,但我不能得到返回码(也不知道什么时候结束)
WMIC:如何使用具有特定工作目录的**进程调用create **?
从包含空格的可变path的batch file中调用.exe
为C ++ Batch设置临时环境variables
如何逃脱“与批量enabledelayedexpansion
在批处理中加速Xcopy
我想通过batch fileexec(start my.bat); 并在batch file中捕获返回代码,但我的命令行有dynamic选项,所以我宁愿做类似的事情;
exec("start cmd "echo hello");
编辑: 但我还没有find一种方法来在命令行上dynamic地创build一个批处理命令列表。 如果有人知道一个办法,我会非常感激。
不需要跨平台,严格的windows(xp-7)
如何通过点分割文件名并获得最后2部分
如何从FTP下载今天和昨天的新数据?
将数字写入文本文件 – batch file
执行多个命令batch file
看看这个: 在Windows上从PHP执行后台进程 。 它解释了一些可能性。
好的,这是我到目前为止的地方。 我想我不需要一个动态的批处理文件,我只能提供参数(杜)。 所以我可以调用exec("start Batch.bat log.txt stdout.txt c:my.exe abc"); 并用一些ajax监视日志文件(就像我现在所做的那样)
REM first 2 params are log filenames set LogFilename=%1 shift set StdOutFilename=%1 shift REM Code to concatonate all following params from here REM http://stackoverflow.com/questions/761615/is-there-a-way-to-indicate-the-last-n-parameters-in-a-batch-file set params=%1 :loop shift if [%1]==[] goto afterloop set params=%params% %1 goto loop :afterloop REM command line is everything after the log-filename param set CommandLine=%params% @echo log: %LogFilename% @echo stdout: %stdOutFilename% @echo command: %CommandLine% if ["%LogFilename%"]==[] exit 255; if ["%stdOutFilename%"]==[] exit 254; if ["%CommandLine%"]==[] exit 253; REM execute command hidden(/B),wait for it to finish so we can get the return code (/WAIT) and output to stdlog @start /B /WAIT %CommandLine% >> %stdOutFilename% REM log return code "RET X" @echo RET %ERRORLEVEL% >> %LogFilename%
$BatchCommandLine = "start /D $Cwd /B /WAIT execute.bat $LogName %stdLogName $Exe $Params"; $OutputLine = exec( $BatchCommandLine,$Output,$ReturnCode ); if ( $ReturnCode != 0 ) echo "Batch file Failed to execute";
* 编辑:*糟糕,exec()不会在后台启动即使启动。 不过,解决了我的其他问题…
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。