2016-08-18 40 views
0

我有這個php代碼,我想在網頁上打印結果,沒有任何內容出現,但是當我在命令行中運行它時,一切都正常工作no var_dump或print_r無法在網頁中回顯

<html> 
<head> 
<title>hello</title> 
</head> 
<body> 
<?php 
$str =exec("python mainsummy.py",$output,$return_var); 
#return_var int 
#output array 
var_dump ($output); 
print_r($output); 
echo "the 4 element \n"; 
echo $output[4]; 
print $output[4]; 
?> 
</body> 
</html> 

這是出現在網頁:

array(0) { } Array () the 4 element 

,這裏是什麼出現在CLI:

<html><head><title>hello</title></head><body>array(5) { [0]=> string(269) "De jure (/dᵻ ˈdʒʊəriː/, /deɪ-/; Classical Latin: de iure [deː ˈjuːrɛ]) is an expression that means \"of right, by right, according to law\" (literally \"from law\"), as contrasted with de facto, which means \"in fact, in reality\" (literally \"from fact\")." [1]=> string(150) "The terms de jure and de facto are used instead of \"in law\" and \"in practice\", respectively, when one is describing political or legal situations." [2]=> string(178) "In a legal context, de jure is contrasted to de facto practices, where, for example, the people obey a contract as though there were a law enforcing it, yet there is no such law." [3]=> string(95) "Ahmad, however, was in practice (de facto) the actual Sultan, and his brother was a figurehead." [4]=> string(117) "Thus, Egypt was by Ottoman law de jure a province of the Ottoman Empire, but de facto was part of the British Empire."}Array( [0] => De jure (/dᵻ ˈdʒʊəriː/, /deɪ-/; Classical Latin: de iure [deː ˈjuːrɛ]) is an expression that means \"of right, by right, according to law\" (literally \"from law\"), as contrasted with de facto, which means \"in fact, in reality\" (literally \"from fact\"). [1] => The terms de jure and de facto are used instead of \"in law\" and \"in practice\", respectively, when one is describing political or legal situations. [2] => In a legal context, de jure is contrasted to de facto practices, where, for example, the people obey a contract as though there were a law enforcing it, yet there is no such law. [3] => Ahmad, however, was in practice (de facto) the actual Sultan, and his brother was a figurehead. [4] => Thus, Egypt was by Ottoman law de jure a province of the Ottoman Empire, but de facto was part of the British Empire.)the 4 element Thus, Egypt was by Ottoman law de jure a province of the Ottoman Empire, but de facto was part of the British Empire.Thus, Egypt was by Ottoman law de jure a province of the Ottoman Empire, but de facto was part of the British Empire.</body></html> 
+0

它可能是用戶角色問題,即網絡服務器作爲一個不同的用戶運行,並且該用戶沒有權限 –

+0

不,我試着用不同的用戶(root和非root),並給出相同的結果 –

+0

是'mainsummy.py '正在執行?我會從PHP提供完整的文件路徑。我還將python腳本寫入某處的日誌,以確保它正在運行,同時調試了PHP腳本。 –

回答

0

你應該ü請更新您的執行程序以確保您以特定用戶的身份默認登錄,然後再運行該命令,因爲這可能是一個權限問題。

例如(假設你是在Linux上)如果你想確保它被用戶「根」與權限運行...

exec("sudo -u root -S python mainsummy.py",etc,etc); 

也可以是「mainsummy的位置。 py「腳本。在PHP中,您正在假設它知道文件實際存在的位置。嘗試使用它的完整路徑。

exec("python '/var/full/path/to/file/mainsummy.py'",etc,etc); 
+0

是的,我嘗試了root用戶,並在命令中添加了sudo,我還使用了完整路徑/home/userXX/Desktop/mainsummy.py,我剛從上面的代碼中刪除。 仍是同樣的問題。 –

0

的問題是一個許可服務器側: 在/ etc添加www數據Apache的用戶許可/ sudoers的

1)納米的/ etc/sudoers的

2)當我解決了我的溶液加入這一行到底 www數據ALL = NOPASSWD:ALL

3)就是這樣,現在使用EXEC()一直記得命令之前使用須藤

exec(「sudo python /FULL_PATH/mainsummy.py",$output,$return_var);

相關問題