2009-01-21 13:27 阅读 34


I have this simple php script

echo '<pre>';

// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = $output = system ("~/public_html/cgi-bin/ &> ~/public_html/errors.txt",$retval);

// Printing additional info
echo '
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;

Which relies on


for i in ~/mail/home/user/mail/*
grep -i Value $i . &> ~/public_html/yesno.txt;

However, all that is display in the b rowser is Retval 1, and no error gets recorded to either of the textfiles. Have I mixed stderr and stdout incorrectly, or missed something else?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dpd2349 dpd2349 2009-01-21 13:49

    $last_line = $output = system ("~/public_html/cgi-bin/ &> ~/public_html/errors.txt",$retval);

    The above line runs and redirects all the output it produces to errors.txt. Therefore, there is no output left to assign to $output (and $last_line). You'll find your last line (together with the rest of the output) in errors.txt.

    If not, try running the shell script directly and see if it produces any output at all.

    点赞 评论 复制链接分享