0

Is it possible to transmit both input and output of a system command in the CLI - a command which would be executed through/by node.js?

I'm interested if it's possible to run something like:

ssh root@localhost

And get all the inputs and outputs provided by ssh, including everything after a successful login.

I've read on the matter and I've came up with this so far:

var spawn = require('child_process').spawn;
var ssh = spawn('ssh', ['root@localhost'], { stdio: 'inherit' });
var me = {};

ssh.stdout.on('data', console.log);

But it doesn't handle my inputs quite well.

Another question which I have here - is it possible to transmit (over network) all the inputs / outputs to clients and alike and allow user to interact with the command from the remote side?

1
  • Why doesn't it handle your inputs quite well? Do note that ssh.stdout is a stream, and you may have to retrieve multiple chunks. Commented Apr 11, 2016 at 11:57

1 Answer 1

2

You may want to take a look at a library such as simple-ssh. It should make your life simpler.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.