1

I have a nodejs daemon running on my server, I would like to give him some input on stdin and read it stdout from a Rails controller, is it possible with Ruby?

I am looking at Open3 but it seems to give me only the chance to spawn a new process.

I need the keep the nodejs process running because the starting overhead is too high to be called at every request.

ciaoben
  • 3,138
  • 4
  • 27
  • 42

1 Answers1

0

In general there is no way to attach to a running process's IO streams unless it was set up to do so initially. It is easy if, for example, the process was set up to read from a pipe: just have Ruby write to that pipe like any other file (this is what the Open3 lib does).

For a daemon usually there are more proper ways to interact with it than hijacking its input with a pipe, though it depends on the particular daemon you are running and how it is being managed by the OS. For example, sockets are a popular way to communicate to a running process on *nix systems.

Max
  • 21,123
  • 5
  • 49
  • 71