PHP exec或shell_exec不在Windows Wamp上返回进程ID(PID)

时间:2013-05-17 15:30:51

标签: php windows ffmpeg shell-exec pid

我在Windows 7上,使用WampServer,并尝试使用FFMPEG。

编码有效,但我无法从exec()获取进程ID 方法和shell_exec()方法。

这是我的代码:

$cmd = C:\ffmpeg\bin\ffmpeg.exe -i "C:\...\4ch.wav"  -ar 44100 -ab 48000 -f mp3 -y "C:\...\enc_4ch.mp3"

这是我尝试用shell_exec做的:

shell_exec("nohup $cmd > /dev/null & echo $!");

用exec:

exec("nohup " . $this->_command . " > /dev/null 2>/dev/null &") ; // returns null
exec("nohup " . $this->_command . " > /dev/null 2>&1 &"); // also returns null 

请让我知道我做错了什么,因为我以后要使用以下方法来检查我的进程是否仍在运行:

private function is_process_running($proccess_id) 
    { 
        exec("ps $proccess_id", $process_state);
        return (count($process_state) >= 2);
    }

谢谢你的推荐

1 个答案:

答案 0 :(得分:0)

您正在使用echo $!来获取进程ID,并且该特定命令在Windows上不可用,因为它是 unix shell 命令。过程链接应该有效:How to get PID from PHP function exec() in Windows?