我正在嘗試在 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 關注
- 180 瀏覽
添加回答
舉報
0/150
提交
取消