Skip to main content
1 of 4
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k

On systems where pipes are bidirectional (NetBSD, FreeBSD, SVR4-derived Unices (all those where pipes use STREAMS at least), but not Linux):

node foo.js <&1 | node bar.js >&0 

Beside the named pipe already mentioned, you can also use a socketpair:

perl -MSocket -e ' socketpair(A, B, AF_UNIX, SOCK_STREAM, PF_UNSPEC); if (fork) { open STDIN, "<&A"; open STDOUT, ">&B"; exec "node", "foo.js"; } else { open STDIN, "<&B"; open STDOUT, ">&A"; exec "node", "bar.js"; }' 
Stéphane Chazelas
  • 586.3k
  • 96
  • 1.1k
  • 1.7k