简体   繁体   English

PHP exec 和 shell_exec:没有 output

[英]PHP exec and shell_exec: no output

Yesterday I asked this question Building g++ via PHP: no build output昨天我问了这个问题Building g++ via PHP: no build output

That part is solved, but now I now have a similar/related problem.那部分已经解决了,但现在我有一个类似/相关的问题。

When I run the compiled executable (see other question) via my browser address bar, the output is printed to the browser window as expected.当我通过浏览器地址栏运行编译后的可执行文件(参见其他问题)时,output 按预期打印到浏览器 window 。

However,I want to use it within PHP and get the output via the return of the exec or shell_exec functions.但是,我想在 PHP 中使用它,并通过 exec 或 shell_exec 函数的返回获得 output。 I have tried various things, including the following:我尝试了各种方法,包括以下内容:

$output = "test.cgi";

echo shell_exec($output);

echo shell_exec("$output 2>&1");

echo system($output);

Nothing works..什么都行。。

Internally, the executable is c code, compiled by g++, and is using print_f.在内部,可执行文件是 c 代码,由 g++ 编译,并使用 print_f。 That should output to STDOUT by default accoding to the specs, so I do not understand why this isn't working.这应该 output 默认为 STDOUT 符合规范,所以我不明白为什么这不起作用。

Can anyone help?任何人都可以帮忙吗?

For anyone with the same problem, I found the solution: exec needed an absolute path to the file对于任何有同样问题的人,我找到了解决方案: exec 需要文件的绝对路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM