从PHP使用system()执行程序时出错:抛出';std::logic_error';


Error executing a program using system() from PHP: terminate called after throwing an instance of 'std::logic_error'

以下是我的index.php 中的一段代码

<?php
/*cmd is a program wittern by another people that I do not know much*/
$cmd="absolutePath/cmd";
$ret=0;
system($cmd,$ret);
?>
<p id="return"><?php echo $ret?></p>

如果我只是在命令行中执行程序,如下所示:$ absolutePath/cmd然后echo $?我得到0,这是正确的

如果我在命令行中执行index.php,如下所示:php -f index.php我在输出中得到了<p id="return">0</p>,这是正确的。

然而,如果我在浏览器(chrome和IE(中打开网页,我得到<p id='return'>134</p>和错误消息:

在抛出"std::logic_error"的实例后调用terminate
what((:basic_string::_S_construct null无效中止

我在stackoverflow上发现的这个问题看起来是一样的:从PHP执行praat时出错:抛出';MelderError';在抛出的异常不同时中止。

基于PHP系统文档,System(command,return_var(:

如果存在return_var参数,则已执行命令的返回状态将写入该变量

因此,返回状态为134。128之后的退出状态,即128+n,其中n是一个小正数,通常意味着程序因信号"n"而崩溃。因此,它是信号6。根据该链接,信号6的意思是"中止信号"。

所以,我的猜测是,外部程序$cmd可能不是从浏览器运行的。