dongyigua4468 2016-02-01 16:55
浏览 257
已采纳

php system()不返回最后一行输出

I have a script that runs youtube-dl . I run that through a php file using system() like so:

$output = system(getenv("YOUTUBEDL_EXE") . " --no-color -f \"mp4\" \"5uR4JucaZ5I\" -o \"/tmp/%(id)s-%(format)s.%(ext)s\"",  $retVal);

The id of the video is not correct (on purpose) and the output I get when I run it on my terminal (linux) is this:

[youtube] 5uR4JucaZ5I: Downloading webpage
[youtube] 5uR4JucaZ5I: Downloading video info webpage
ERROR: 5uR4JucaZ5I: YouTube said: This video does not exist.

BUT, when I run it through system, the $output variable returns the second line, not the last one

[youtube] 5uR4JucaZ5I: Downloading video info webpage

I still get proper exit codes (that it is not completed successfully) but cannot get the last line with the ERROR: tag so I can parse the error. Unfortunately this is the only way to get the error as it only returns 1 on any error type.

(youtube-dl is written in python and its executable starts with :

#!/usr/bin/env python

and a zip header (PK ....) )

Any pointers in how to get the last line are massively welcomed!

Thanks

  • 写回答

1条回答 默认 最新

  • duanliao3826 2016-02-01 17:18
    关注

    The last line is an error and gets written to STDERR and not STDOUT. You need to redirect the STDERR to STDOUT if you want to get errors with PHP, you can do that by adding 2>&1 at the end of your command.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效