PHP Exec无法启动应用程序 [英] PHP Exec Does not Launch Application
问题描述
我正在尝试通过Web界面运行应用程序-更具体地说是Source Dedicated Server.我正在使用以下代码进行此操作:
I'm attempting to run an application - more specifically a Source Dedicated Server - through a web-interface. I am doing this using the following code:
$old_path = getcwd();
chdir("[PATH]");
$tmp = exec("srcds -console -game tf +map ctf_2fort");
chdir($old_path);
不幸的是,该网站挂起,并且从未加载.通过命令提示符运行相同的命令非常有效,运行exec("echo %cd%")
输出正确的路径,我可以运行文件夹中的其他内容(例如仅回显%time%
的示例.bat),依此类推.
Unfortunately, the site hangs, and is never loaded. Running the same exact command through the command prompt works perfectly, running exec("echo %cd%")
outputs the correct path, I can run other things (such as a sample .bat that simply echoes %time%
) from the folder, so on and so forth.
我已经能够通过将stdout重定向到/dev/null/
(用以下内容替换$tmp =
行)来加载网站:
I have been able to make the site load by redirecting stdout to /dev/null/
(replacing the $tmp =
line with the following:)
$tmp = exec("srcds -console -game tf +map ctf_2fort > /dev/null");
尽管这允许网站加载,但应用程序永远不会运行(并且该过程不会出现在任务管理器中).
While this allows the site to load, the application is never run (and the process doesn't appear in the task manager).
我尝试输出到文件,但这仅输出两行,第一行显示Using breakpad minidump system
,第二行为空.它还不会启动该应用程序.
I've tried outputting to a file, but this simply outputs two lines, the first one saying Using breakpad minidump system
, the second one empty. It also doesn't launch the application.
$tmp = exec("srcds -console -game tf +map ctf_2fort > tmp.txt");
我对应该做的事不知所措-我对PHP还是很陌生,因此,如果有任何明显的我想念的地方,请这么做.
I'm at loss as to what I should do - I'm fairly new to PHP, so if there's anything obvious I'm missing, please do say so.
推荐答案
尝试将2>&1
添加到命令中.您还可以指定是否要将碰巧显示的输出的每一行显示为数组,如下所示:
Try adding 2>&1
to the command. You can also specify if you want each line of the output from what happened to be displayed as an array, like so:
$tmp = exec("srcds -console -game tf +map ctf_2fort 2>&1", $what_happened);
print_r($what_happened);
如果启用了安全模式,则可能会遇到一些问题...如果上述建议对您不起作用,您还可以查看 passthru()命令.
If safe mode is on, you might run into some problems though... If the above suggestion doesn't work for you, you might also check out the system() and/or passthru() commands.
这篇关于PHP Exec无法启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!