1

Say I have

node foo.js | node bar.js

is there a way to pass a handle on foo's stdin to bar?

I have a rare case where I'd like to communicate backwards in the pipeline.

At the least I know that I could send node bar.js the pid of node foo.js. Given that pid, on *nix, I should be able to write to foo's stdin using:

/proc/<pid>/fd/0

but is there a way to do the same on MacOS?

8
  • 1
    IMHO this is best asked on StackOverflow. Commented Nov 29, 2017 at 21:39
  • I did actually, I asked it about a week ago on SO: stackoverflow.com/questions/47270986/pass-handle-down-pipeline Commented Nov 29, 2017 at 22:27
  • maybe I should start a bounty on it Commented Nov 29, 2017 at 22:28
  • 1
    /proc/<pid>/fd/0 would get you a handle on pid's stdin but what would you do with that? What if it's a terminal device, a regular file, a socket, a pipe? Here, it looks like you want foo.js stdin to be a pipe (or other IPC channel like a socketpair) and bar.js to have a file descriptor to the other end of that pipe. Commented Nov 29, 2017 at 23:48
  • It sounds very similar to your earlier Communicate backwards in a pipe question. Commented Nov 29, 2017 at 23:49

1 Answer 1

1

In the general case no, because the write handle of the stdin of foo is only in the hands of its parent process (foo only sees the read handle)... You have to set up a specific pipe (anonymous or FIFO) between the two; and this is better anyway because you don't know what would happen if bar wrote to that handle as the same time as foo's parent.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.