简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM