dotwc62080 2015-04-16 19:48
浏览 666

php中exec()的输出是空数组

I have the following code to execute mysqldump using exec(). It was not working and I wanted figure out what output the command line throws. So I printed $output and $worked. But all I get is 1 and an empty array.

Accordong to manual: If the output argument is present, then the specified array will be filled with every line of output from the command. But why is this throwing an empty array? I am including 2>&1 at the end of command as some post suggested, but still not working. I want to know what the terminal is outputting when this command is being executed.

And what does $worked outputting 1 mean?

Any help will be greatly appreciated!

Script:

$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);

Outputs:

1
Array ( ) 
  • 写回答

1条回答 默认 最新

  • duanjing1276 2015-04-16 20:11
    关注

    I want to know what the terminal is outputting when this command is being executed.

    Nothing! (And had you simply tried it yourself you'd have seen that immediately). Your command directs the result of mysqldump to the file at the path denoted by $mysqlExportPath. I don't know why you expect it to go to stdout instead.

    Perhaps some line breaks would help to make your code a little (no, substantially!) more readable:

    $command
      = 'mysqldump --opt'
      . ' -u ' . $db['username']
      . ' -p' . $db['password']
      . ' --databases ' . $db['database']
      . ' > ' . $mysqlExportPath   // <---- Here you go!
      . ' 2>&1';
    

    Remove the redirection, or find the data inside the file $mysqlExportPath; your call!

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大