2009-01-21 45 views
0

我有這個簡單的PHP腳本PHP調用bash的問題

<?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 rowser顯示RETVAL 1,沒有錯誤被記錄到任一文本文件中。我是否錯誤地混合了stderr和stdout,或者錯過了其他的東西?

回答

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腳本,看看它是否產生任何輸出。

+0

我在沒有shell訪問權限的共享服務器上,必須通過上傳並通過瀏覽器運行,所以我無法直接運行它。絕對沒有任何內容存儲在errors.txt中 – 2009-01-21 14:02:18