Closed rodion-k closed 3 years ago
diff <(echo 1) <(echo 2)
is a shell syntax not supported within the Posix standard, it works in Bash (and ZSH and some other)
/bin/bash -c 'diff <(echo 1) <(echo 2);'
1c1
< 1
---
> 2
but not in posix:
/bin/bash --posix -c 'diff <(echo 1) <(echo 2);'
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `diff <(echo 1) <(echo 2);'
the bash example only to show how it could be simulated, the actual shell in use is /bin/sh
:
/bin/sh -c 'diff <(echo 1) <(echo 2);'
/bin/sh: 1: Syntax error: "(" unexpected
This is equivalent with the long variant:
/bin/sh -c '{ (diff <(echo 1) <(echo 2)) <&3 3<&- 3>/dev/null & } 3<&0; trap "" INT TERM QUIT HUP;pid=$!; echo $pid >&3; wait $pid; RC=$?; echo $RC >&3; exit $RC' 3>&2
/bin/sh: 1: Syntax error: "(" unexpected
As no PID is being output on stream 3, it could not be determined, hence the
Could not determine PID
exception message.
Long description now, but it contains already the solution. Change the command to bash:
\Amp\Loop::run(function() {
$process = new \Amp\Process\Process('/bin/bash -c "diff <(echo 1) <(echo 2)"');
yield $process->start();
yield $process->join();
});
The following code:
Raises exception:
Actual command executed is:
{ (diff <(echo 1) <(echo 2)) <&3 3<&- 3>/dev/null & } 3<&0; trap "" INT TERM QUIT HUP;pid=$!; echo $pid >&3; wait $pid; RC=$?; echo $RC >&3; exit $RC
Executing it in terminal gives: