Php system() / exec() don't return output

前端 未结 2 1802
误落风尘
误落风尘 2020-12-17 04:37

For common commands like \'ls\', exec() works fine, eg:

exec(\'ls\',$output,$retval);
var_dump($output,$retval);
// $output contains an array of filenames, a         


        
相关标签:
2条回答
  • It sounds like the program is outputting its warnings to standard error rather than standard output. exec will only catch standard output. I don't know for certain that standard error is always sent to the apache error log, but it seems likely.

    If you don't need compatibility with non-*nix systems, you can redirect standard error to standard output by appending 2>&1 to the command:

    exec('some_command --option 2>&1', $output, $ret);
    

    This should both make the warnings available to your php program and prevent unnecessary logging.

    0 讨论(0)
  • 2020-12-17 04:55

    All the output was being sent to httpd/error_log when for some * reason, when the application found a warning (something internal, not even fatal)

    My solution: When there is no output, assume it failed. My apache logs are going to get dirty, but whatever.

    0 讨论(0)
提交回复
热议问题