2010-05-20 120 views
0

我目前正在尝试通过PHP获取SoX。这一切迄今为止都有效,但我没有收回输出。我已经读过,可能会将stderr也路由到输出“2> & 1”..问题是,这似乎不适用于Windows机器。PHP执行 - 缺少输出

还有其他想法吗?

代码如下:

exec($path2sox . '/sox ' . $cmd . ' 2>&1', $output = array(), $result);

,而该文件被创建(所以基本SOX命令是好的,我也测试了它到底在Windows命令行相同的命令),但没有结果,也没有输出给什么作为回报(SoX的详细程度设置为4,这是完整的输出)

我想,windows并不理解2> & 1声明,但是如何克服?

P.S:如下建议,我也试过这个

$output = array(); 
echo "Executing: [$path2sox/sox $cmd]"; 
exec("$path2sox/sox $cmd", $output, $result); 
echo "Result: "; 
var_dump($result); 
echo "\n
Output: "; var_dump($output);

其中输出是:

Executing: [I:\SoX/sox --guard -V4 "somedirectory/test.wav" --compression "320.2" "somedirectory/test.mp3"]Result: int(0)


Output: array(0) { }

文件正确创建...

+1

请分享您使用的代码。 – Josh 2010-05-20 20:21:54

回答

4

你传递的第二输出数组参数?

http://us2.php.net/manual/en/function.exec.php

string exec (string $command [, array &$output [, int &$return_var ]]) 

输出

如果输出参数存在,则 指定数组将 充满来自 命令输出的每一行。作为\ n的尾随空格,如 不包含在此数组中。 请注意,如果已经有数组 包含某些元素,exec()会将 追加到数组的末尾。如果 不希望函数附加 元素,请在将数组传递给exec()之前,在数组 上调用unset()。

+0

我怀疑这是他的问题,这就是为什么我要求代码。对不起,我今天没有赞成! – Josh 2010-05-20 20:24:40

+0

没什么大不了的,代表对我来说真的没有什么意义了。 ;) – Amber 2010-05-20 20:27:28

+0

我觉得我的感觉和你的鞋子一样。与我一样多的代表超过10倍,并且您在网站上的时间更少。不错的工作:-) – Josh 2010-05-20 21:21:32

1

我怀疑你可能是正确的,Windows不喜欢2>&1声明。当您尝试时,您会看到什么:

$output = array() 
echo "Executing: [$path2sox/sox $cmd]"; 
exec("$path2sox/sox $cmd", $output, $result); 
echo "Result: "; 
var_dump($result); 
echo "\n<br>Output: "; 
var_dump(output); 
+0

没有2>&1 ..也没有尝试 – japanitrat 2010-05-21 00:39:22

+0

请编辑您的问题并发布您看到的输出... – Josh 2010-05-21 01:27:49

+0

由于结果为0,那将显示*表示呼叫成功。在命令行下运行'I:\ SoX/sox --guard -V4“somedirectory/test.wav”--compression“320.2”“somedirectory/test.mp3”时会发生什么? – Josh 2010-05-21 13:29:20