1

Here is a piece of code in my 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>

If I just exec the program in command line like this: $ absolutePath/cmd and then echo $? I get 0, which is correct

if I exec the index.php in command line like this: php -f index.php I get <p id="return">0</p> in the output, which is correct.

However if I open the web page in browser(both chrome and IE), I get <p id='return'>134</p> and the error message:

terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid Aborted

the problem looks same with this one I found on stackoverflow: Error executing praat from PHP: terminate called after throwing an instance of 'MelderError' Aborted while the exception throwed is different.

Community
  • 1
  • 1
Alaya
  • 3,287
  • 4
  • 27
  • 39

1 Answers1

0

Base on the PHP System docs, System(command, return_var):

If the return_var argument is present, then the return status of the executed command will be written to this variable.

So, the return status is 134. Exit statuses after 128, ie., 128+n where n is a small positive number usually mean that the program crashed with signal 'n'. so, it is signal 6. According to this link, Signal 6 means 'Abort signal'.

So, my guess is, the external program $cmd may not be run from a browser.

Rajesh
  • 3,743
  • 1
  • 24
  • 31
  • It turns out that the reason is that the www-data user didn't have the env variable $HOME. – Alaya Aug 04 '14 at 00:57