运行PHP"exec()";在Windows的后台? [英] Running a PHP "exec()" in the background on Windows?

查看:581
本文介绍了运行PHP"exec()";在Windows的后台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个脚本,该脚本使用psexec调用另一个脚本,该脚本调用psexec来运行我的命令行程序.

I've created a script that uses psexec to call another script which calls psexec to run a command line program of mine.

之所以调用psexec和其他脚本如此之多,仅是因为我的PHP脚本不必等到该过程完成就可以将其输出到浏览器.

The reason for so many calls to psexec and other scripts is solely so that my PHP script doesn't have to wait for the process to finish before finishing it's output to the browser.

是否有一种无需使用psexec即可做到这一点的方法?我在psexec上遇到问题,所以我想将其从程序中完全删除.

Is there a way I can do this without needing to use psexec? I'm having issues with psexec so I'd like to just completely remove it from my program.

我正在运行Windows 2008

I'm running Windows 2008

我更改了标题,我想这将是一个更准确的标题.我在exec()上的php.net页面上找到了If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.,但不确定如何做到这一点.

I changed the title, I guess this would be a more accurate title. I found out the If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends. on php.net's page on exec(), but wasn't sure how to do that.

推荐答案

在命令行中包含重定向:

Include a redirection in the command line:

exec('program.exe > NUL')

或者您可以修改程序以显式关闭标准输出,在C语言中将是

or you could modify your program to explicitly close standard output, in C this would be

CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE));

您可能需要(文档中没有说明)同时重定向/关闭标准输出和标准错误:

It is possible (the documentation doesn't say) that you might need to redirect/close both the standard output and standard error:

exec('program.exe > NUL 2> NUL')

CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE));
CloseHandle(GetStdHandle(STD_ERROR_HANDLE));

这篇关于运行PHP"exec()";在Windows的后台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆