我有這個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>
它可能是用戶角色問題,即網絡服務器作爲一個不同的用戶運行,並且該用戶沒有權限 –
不,我試着用不同的用戶(root和非root),並給出相同的結果 –
是'mainsummy.py '正在執行?我會從PHP提供完整的文件路徑。我還將python腳本寫入某處的日誌,以確保它正在運行,同時調試了PHP腳本。 –