2015-04-23 222 views
1

我在/ var/www文件夾中有以下index.php文件。通過PHP的交互式shell命令

<html> 
<?php 
$output = shell_exec("/home/ak/Documents/Translation/mosesdecoder/bin/moses -f /home/ak/Documents/Translation/ourOwnHinNorm/working/binarisedModel/moses.ini -input-file /home/ak/Documents/Translation/input.txt > /home/ak/Documents/Translation/output.txt"); 
//$output = shell_exec("cat /home/ak/Documents/Translation/instructions.txt"); 
echo $output; 
?> 
</html> 

的代碼試圖運行moses程序從input.txt讀取輸入和輸出寫入output.txt。我在我的Ubuntu終端上運行了上面編寫的moses命令,它工作正常。

但是,當我通過瀏覽器運行index.php時,即使經過很長時間,output.txt仍保持爲空。

注意:我運行了chmod -R 775 /home/ak/Documents/Translation/,因此我可以訪問和執行該目錄中的文件。作爲一項測試,我對註釋行進行了取消註釋(第shell_execindex.php),該行旨在打印放置在同一文件夾中的instructions.txt的內容。然後,通過瀏覽器運行index.php,在瀏覽器上打印instructions.txt的內容。

任何想法,爲什麼第一個shell_exec通過瀏覽器運行時失敗?

+0

嘗試從終端運行此 須藤-u www數據/家/ AK /文檔/翻譯/ mosesdecoder /斌/摩西-f /家庭/ AK/Documents/Translation/ourOwnHinNorm/working/binarisedModel/moses.ini -input-file /home/ak/Documents/Translation/input.txt> /home/ak/Documents/Translation/output.txt 然後檢查output.txt。如果它爲空 - 您必須檢查www-data用戶的權限。 –

+0

output.txt得到填充運行您建議的命令...所以我認爲沒有問題的權限 – avinash

回答

0

加入這一行/home/ak/.bashrc

export PATH=$PATH:/home/ak/Documents/Translation/mosesdecoder/bin 

打開一個新的終端輸入moses,以測試它是否工作。現在

更換

$輸出=了shell_exec(「/家/ AK /文檔/翻譯/ mosesdecoder /斌/摩西-f /家庭/ AK /文檔/翻譯/ ourOwnHinNorm /工作/binarisedModel/moses.ini -input-file /home/ak/Documents/Translation/input.txt> /home/ak/Documents/Translation/output.txt「);

有:

$output = shell_exec("moses -f /home/ak/Documents/Translation/ourOwnHinNorm/working/binarisedModel/moses.ini -input-file /home/ak/Documents/Translation/input.txt > /home/ak/Documents/Translation/output.txt"); 
+0

它也沒有產生任何輸出...並且我也提供完整路徑的可執行文件在shell命令,所以我不認爲只是將其添加到環境路徑變量將有所作爲......但無論如何 – avinash