doupa1883 2009-01-21 13:27
浏览 34
已采纳

php调用bash问题

I have this simple php script

<?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;
?>

Which relies on 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

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 2009-01-21 13:49
    关注

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

    The above line runs srch.sh 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大