0

我有这个简单的 php 脚本

<?php
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/srch.sh &> ~/public_html/errors.txt",$retval);

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

依赖于 srch.sh:

#!/bin/bash

for i in ~/mail/home/user/mail/domain.com/josh/cur/*
do
grep -i Value $i . &> ~/public_html/yesno.txt;
done

但是,在 b 行器中显示的只是 Retval 1,并且没有错误记录到任何一个文本文件中。我是否错误地混合了标准错误和标准输出,或者错过了其他东西?

4

1 回答 1

1

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

上面的行运行 srch.sh 并将它产生的所有输出重定向到 errors.txt。因此,没有输出可以分配给 $output(和 $last_line)。您将在errors.txt 中找到您的最后一行(连同其余的输出)。

如果没有,请尝试直接运行 shell 脚本,看看它是否会产生任何输出。

于 2009-01-21T13:49:12.143 回答