Zlatan Omerovic
Zlatan Omerovic

Reputation: 4097

Transmitting command's input and output through Node.js

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?

Upvotes: 0

Views: 56

Answers (1)

christophetd
christophetd

Reputation: 3874

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

Upvotes: 2

Related Questions