[英]Output of exec() in php is empty array
我有以下代碼使用exec()
執行mysqldump
。 它沒有用,我想弄清楚命令行拋出什么輸出。 所以我打印了$output
和$worked
。 但是我得到的只是1
和一個空數組 。
按照手冊進行操作: If the output argument is present, then the specified array will be filled with every line of output from the command.
但是為什么這會拋出一個空數組? 正如某些帖子所建議的那樣,我在命令末尾包含2>&1
,但仍然無法正常工作。 我想知道執行此命令時終端輸出的內容。
$worked
輸出1
是什么意思?
任何幫助將不勝感激!
腳本:
$command='mysqldump --opt -u ' .$db['username'] .' -p' .$db['password'] .' --databases ' .$db['database'] .' > '.$mysqlExportPath .' 2>&1';
$output=array();
exec($command,$output,$worked);
print $worked.'<br>';
print_r($output);
輸出:
1
Array ( )
我想知道執行此命令時終端輸出的內容。
沒事 ! (如果您只是自己嘗試過,您會立即看到的)。 您的命令將mysqldump
的結果定向到$mysqlExportPath
表示的路徑中的文件。 我不知道您為什么期望它轉為標准輸出 。
也許一些換行符可以使您的代碼更具可讀性(不, 實質上是 !):
$command
= 'mysqldump --opt'
. ' -u ' . $db['username']
. ' -p' . $db['password']
. ' --databases ' . $db['database']
. ' > ' . $mysqlExportPath // <---- Here you go!
. ' 2>&1';
刪除重定向,或在文件$mysqlExportPath
找到數據; 您的來電!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.