php exec和shell_exec无法正常工作 [英] php exec and shell_exec not working

查看:88
本文介绍了php exec和shell_exec无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在服务器上运行一个exe文件,然后将输出返回到浏览器屏幕. exe文件需要输入文件,然后在屏幕上返回数据.

I want to run an exe file on my server and return the output to the browser screen. The exe file takes a input file and then returns data on the screen.

为什么此代码不起作用?

Why is this code not working?

$output = shell_exec('myprogram < INP.DAT');
echo "<pre>" . var_export($output, TRUE) ."</pre>\\n";

它在浏览器屏幕上显示"NULL".我也尝试过exec().在那里返回"Array()".

It displays "NULL" on the browser screen. I have also tried exec(). There it returns "Array()".

推荐答案

One of the comments on the shell_exec manual page says:

请注意以下不一致之处:shell_exec()和backtick运算符将在命令输出为空时不返回字符串-而是返回NULL.

Beware of the following inconsistency: shell_exec() and the backtick operator will not return a string if the command's output is empty -- they'll return NULL instead.

这将与''返回false进行严格比较.

This will make strict comparisons to '' return false.


如果PHP处于安全模式,则可能已禁用.

shell_exec()(反引号的功能等效项)
当PHP以安全模式运行时,此功能被禁用.

shell_exec() (functional equivalent of backticks)
This function is disabled when PHP is running in safe mode.

exec()
您只能在safe_mode_exec_dir中执行可执行文件.出于实际原因,当前不允许在可执行文件的路径中包含..组件. escapeshellcmd()在此函数的参数上执行.

exec()
You can only execute executables within the safe_mode_exec_dir. For practical reasons it's currently not allowed to have .. components in the path to the executable. escapeshellcmd() is executed on the argument of this function.

您可以使用 phpinfo() 检查服务器的PHP设置.功能.

You can check your server's PHP settings with the phpinfo() function.

这篇关于php exec和shell_exec无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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