PHP exec - 缺少输出

发布于 2024-09-02 00:43:58 字数 853 浏览 6 评论 0原文

我目前正在尝试让 SoX 通过 PHP 工作。到目前为止一切正常,但我没有得到输出。我已经读到,人们也可能将 stderr 路由到带有“2>&1”的输出。问题是,这似乎在 Windows 机器上不起作用。

还有其他想法吗?

代码如下:

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

虽然文件被创建(所以基本的 sox 命令是可以的,我也在 Windows 命令行中测试了完全相同的命令),但结果和输出都没有给出任何回报(SoX 详细程度设置为 4,这是完整输出)

我想,Windows 不理解 2>&1 语句,但是如何克服这个问题?

PS:正如下面所建议的,我也尝试过这个,

$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)


输出:数组(0){ }

File was created properly ...

I am currently trying to get SoX working through PHP. It all works so far, but I don't get the output back. I've already read that one might route stderr also to the output with "2>&1" .. the problem is, this doesn't seem to work on windows machines.

any other ideas?

code is as follows:

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

whereas the file gets created (so basic sox command is okay, i also tested it exactly the same command in the windows commandline), but neither result nor output give something in return (SoX verbosity is set to 4, which is full output)

I suppose, windows doesnt understand the 2>&1 statement, but how can this be overcome?

P.S: as suggested below, I also tried this

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

where the output is:

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


Output: array(0) { }

File was created properly ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

述情 2024-09-09 00:43:58

您是否传递第二个输出数组参数?

https://www.php.net/manual/en/function.exec。 php

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

输出

如果输出参数存在,
那么指定的数组将是
充满了输出的每一行
命令。尾随空白,例如
作为 \n,不包含在此数组中。
请注意,如果数组已经
包含一些元素,exec() 将
追加到数组末尾。如果你
不希望附加该函数
元素,对数组调用 unset()
在将其传递给 exec() 之前。

Are you passing the second output array parameter?

https://www.php.net/manual/en/function.exec.php

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

output

If the output argument is present,
then the specified array will be
filled with every line of output from
the command. Trailing whitespace, such
as \n, is not included in this array.
Note that if the array already
contains some elements, exec() will
append to the end of the array. If you
do not want the function to append
elements, call unset() on the array
before passing it to exec().

╭ゆ眷念 2024-09-09 00:43:58

我怀疑您可能是对的,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);

I suspect you might be right that windows isn't liking the 2>&1 statement. What do you see when you try:

$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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文