On systems with bi-directional pipes (not Linux), you can do:
cmd0 <&1 | cmd1 >&0
On Linux, you can do:
: | { cmd1 | cmd2; } > /dev/fd/0
That works because on Linux (and Cygwin, but generally not other systems) /dev/fd/x
where x
is a fd to a pipe (named or not) acts like a named pipe, that is, opening it in read mode gets you the reading end and in write mode gets you the writing end.
With the yash
shell and its x>>|y
pipeline redirection operator:
{ cmd0 | cmd1; } >>|0
With shells with coproc support:
Dedicated tool approaches (shamelessly copied from answers on this very similar question):
Using pipexec
pipexec [ A /path/to/cmd0 ] \
[ B /path/to/cmd1 ] \
'{A:1>B:0}' '{A:0>B:1}'
Or using dpipe
dpipe cmd0 = cmd1
Or using socat
:
socat EXEC:cmd0 EXEC:cmd1,nofork # using socketpairs
socat EXEC:cmd0,commtype=pipes EXEC:cmd1,nofork # using pipes
I don't know about python
, but that's also relatively easily done in perl
:
perl -e 'pipe STDOUT,STDIN; exec "cmd0 | cmd1"'
You can always also resort to named pipes, but finding unique names for them and some safe directory to create them in, restricting access to them (so other processes can't open them and interfere) and cleanup afterwards become additional problems which are hard to overcome reliably and portably.
In any case, beware of deadlocks!