1

I want to use node.js to capture the output of a shell so that I can send it to another process, and also send input to the shell as if I was a user using the terminal (this is for an automation tool). I have managed to accomplish the latter (sending commands and input to the shell), but I am still missing some of the output from the terminal.

I have posted a specific question here on this problem, but I'm wondering if there is a better way to accomplish the high-level goal. Maybe a node.js script isn't the correct approach. Are there better tools or existing APIs for doing what I want?

umop
  • 2,122
  • 2
  • 18
  • 22

1 Answers1

0

The general solution is to connect the child process to a pseudo terminal (pty) instead of plain pipes. This looks like a normal terminal to the child, but is actually an emulator that allows the parent to interact with it through pipes.

In the shell, this can be done with programs like expect or script. Most high-level languages have a way to run child processes in a pty, maybe using an external library. It looks like the child_pty package is designed to do this in node.js.

yut23
  • 2,624
  • 10
  • 18