从cmd行程序(rtmpdump.exe)捕获PHP exec()输出的替代方法
过去我曾多次使用exec()函数从命令行可执行文件中捕获信息,并打算使用RTMPDump.exe再次执行此操作。PHP代码如下所示,可与我过去使用过的任何其他cmd行示例一起使用,但在本例中,不会产生任何$output:从cmd行程序(rtmpdump.exe)捕获PHP exec()输出的替代方法,php,cmd,rtmp,Php,Cmd,Rtmp,过去我曾多次使用exec()函数从命令行可执行文件中捕获信息,并打算使用RTMPDump.exe再次执行此操作。PHP代码如下所示,可与我过去使用过的任何其他cmd行示例一起使用,但在本例中,不会产生任何$output: $cmd = 'c:\rtmpdump\rtmpdump -r "rtmp://fms.domain.com/live/live_800"'; exec($cmd, $output); foreach ($output as $item){
$cmd = 'c:\rtmpdump\rtmpdump -r "rtmp://fms.domain.com/live/live_800"';
exec($cmd, $output);
foreach ($output as $item){
// do something with this $item
}
我尝试过将Windows命令行放在一个.bat文件中,然后运行该文件,其中ase$output只包含bat文件中回显的内容,而不包含下面显示的输出,这是我从命令行手动运行命令时得到的结果
C:\rtmpdump>rtmpdump -r "rtmp://fms.domain.com/live/live_800"
RTMPDump v2.3
(c) 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team; license: GPL
Connecting ...
INFO: Connected...
ERROR: rtmp server sent error
Starting Live Stream
For duration: 2.000 sec
INFO: Metadata:
INFO: author
INFO: copyright
INFO: description
INFO: keywords
INFO: rating
INFO: title
INFO: presetname Custom
INFO: creationdate Tue May 08 03:00:23 2012
INFO: videodevice Osprey-440 Video Device 1B
INFO: framerate 25.00
INFO: width 480.00
INFO: height 360.00
INFO: videocodecid avc1
INFO: videodatarate 800.00
INFO: avclevel 30.00
INFO: avcprofile 66.00
INFO: videokeyframe_frequency10.00
INFO: audiodevice Osprey-440 Audio Device 1B
INFO: audiosamplerate 22050.00
INFO: audiochannels 1.00
INFO: audioinputvolume 75.00
INFO: audiocodecid mp4a
INFO: audiodatarate 48.00
#######
Download complete
C:\rtmpdump>rtmpdump
程序确实在运行,这不是问题所在,有一个显示视频数据转储的输出文件,因此可执行文件的语法不是问题所在-问题在于是否有任何其他方法可以截获rtmpdump.exe输出到命令窗口的内容,而这些内容不是通过exec()从PHP运行来捕获的
如果重要的话,我感兴趣的是“信息:…”。我正在尝试确定一个实时视频流是否是流式的。服务器正在运行,但我需要知道某个特定流(live_800)是否正在流。尝试功能。多亏了JohnF让我走上了正确的轨道,如果其他新手需要完成这项工作,下面是我如何使用proc_open完成的:
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
$cmd = c:\rtmpdump\rtmpdump -r "rtmp://fms.domain.com/live/live_800 -B 1 -m 3";
$process = proc_open($cmd, $descriptorspec, $pipes);
if (is_resource($process)) {
$stdin = stream_get_contents($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]);
// It is important that you close any pipes before calling proc_close in order to avoid a deadlock
$return_value = proc_close($process);
}
很好的建议,但是没有骰子:(如果命令在命令行上生成的输出
exec
没有捕获,那么它可能是输出到stderr,而不是stdout。我想你必须使用proc\u open
。你能运行命令c:\rtmpdump\rtmpdump-r吗?”rtmp://fms.domain.com/live/live_800">out.txt
在命令提示符下,查看信息行是否显示在终端上或捕获在文本文件中?Salman,已经尝试过了,但没有成功。John F.-proc__open看起来潜力巨大-以前没有机会使用它,所以我期待着尝试这一次!JohnF:call_proc已经打开了新的do或者让我调查这个挑战,所以如果你想添加你的建议作为答案,我会很高兴地接受它,否则我会自己回答并关闭它。