Reputation: 8709
I'm trying to run a linux process in Symfony 5.1 as described here: https://symfony.com/doc/current/components/process.html
use 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;
}
}
No matter what my command line is, I get the following output:
Read from stderr: sh: 1: exec: echo hello: not found
Upvotes: 1
Views: 2073
Reputation: 9460
It is also possible to simply use Process::fromShellCommandline
For example
$process = Process::fromShellCommandline('echo hello');
Upvotes: 1
Reputation: 1319
In the docs you mentioned you can see example: https://symfony.com/doc/current/components/process.html#usage
$process = new Process(['ls', '-lsa']);
Source code for Process constructor: https://github.com/symfony/symfony/blob/5.1/src/Symfony/Component/Process/Process.php#L132
First parameter is:
* @param array $command The command to run and its arguments listed as separate entries
Try $process = new Process(['echo', 'hello']);
not $process = new Process(['echo hello']);
Upvotes: 4