【发布时间】:2019-11-18 08:31:09
【问题描述】:
我无法通过 php 从可执行文件 (a.out) 中获取输出。 我的 php 代码是:
$file = "/path/main.cpp";
$command="cd $path && c++ -lm ".$file;
exec($command);
$output = exec("cd $path && ./a.out");
exec("cd $path && ./a.out > res.txt");
var_dump($output);
所有命令都已执行,但我得到的是空值;
exec("cd $path && ./a.out > res.txt");
这个命令也被执行了,res.txt 是在文件夹中创建的,但是是空文件。 如何解决这个问题呢? 我的操作系统是 CentOS 7
【问题讨论】:
-
好像你想要
popen。 -
关于重定向中的“空文件”,您确定程序实际上会生成任何输出吗?还是说编译成功,
a.out程序存在? -
是的,我从终端检查,没问题,但是通过 php 没有输出
-
也尝试捕获错误输出,看看它是否失败 (stackoverflow.com/questions/3863699/…)。
-
我明白了:sh: ./a.out: Permission denied
标签: php