exec命令用php挂在Windows服务器上。我无数次地用ajax来称呼它(使用“ for”),但我不知道为什么。我已经尝试过:
pclose(popen("start /B ". $command, "w"));
pclose(popen($command_str, 'a'));` // tried with 'w' too
此:
WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($command, 1, true); `
此:
shell_exec('start /B $command');
此:
error_reporting(E_ALL);
$handle = popen($command.' 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);
此:
exec($command_str." >> error.txt 2>&1 &",$out,$code);
我已经尝试了我在stackoverflow中看到的几乎所有内容:
PHP exec() as Background Process (Windows Wampserver Environment)
PHP on a windows machine; Start process in background
,并且已经知道: “如果程序使用此功能启动,则要使其在后台继续运行,必须将程序的输出重定向到文件或其他输出流。否则,将导致PHP挂起,直到执行程序结束。”
没有一个对我有用。附言:我不想像执行popen()那样忽略命令的执行。我希望php等待exec完成并返回。
我要运行的命令是:
$command_str = "sox.exe /audio/123.wav -e signed-integer
123.wav.conv.wav";
我已经放了2>&1,没什么改变
P.S:任何其他指令都会使exec挂起。例如:sox.exe,cd,dir等。
最终代码:
javascript:
for (var i=0; i<resultado.length; i++){
$.ajax({
cache: false,
type: "POST",
url: 'getAudiosFTP.php',
success: function(final){
console.log(final);
}});
}
php:
$resposta=Library::downloadFileFromFtp($Result['server'], $file,
$path_destino, $Result['user'], $Result['password']);
if ($resposta==1){
$convexe_dir = str_replace(array('/'), '\\',
'/sistema/ligacoes/sox/sox.exe');
$command_str = "{$convexe_dir} {$path_destino} -e signed-integer
{$path_destino}.conv.wav 2>&1";
exec($command_str, $output);
unlink($path_destino);
rename("{$path_destino}.conv.wav", $path_destino);
}