我正在尝试在 Symfony 5.1 中运行 Linux 进程,如下所述: https: //symfony.com/doc/current/components/process.htmluse Symfony\Component\Process\Process;(...)$command = 'echo hello';$process = new Process([$command]);$process->start();foreach ($process as $type => $data) { if ($process::OUT === $type) { echo "\nRead from stdout: ".$data; } else { // $process::ERR === $type echo "\nRead from stderr: ".$data; }}无论我的命令行是什么,我都会得到以下输出:Read from stderr: sh: 1: exec: echo hello: not found
2 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
在您提到的文档中,您可以看到示例: https: //symfony.com/doc/current/components/process.html#usage
$process = new Process(['ls', '-lsa']);
流程构造函数的源代码: https://github.com/symfony/symfony/blob/5.1/src/Symfony/Component/Process/Process.php#L132
第一个参数是:
* @param array $command The command to run and its arguments listed as separate entries
尽量$process = new Process(['echo', 'hello']);
不要$process = new Process(['echo hello']);
料青山看我应如是
TA贡献1772条经验 获得超8个赞
也可以简单地使用Process::fromShellCommandline
例如
$process = Process::fromShellCommandline('echo hello');
- 2 回答
- 0 关注
- 145 浏览
添加回答
举报
0/150
提交
取消