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.

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

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧