I'm trying to run a ssh child process in node.js and control it through my program. My code:
var util = require('util');
var spawn = require('child_process').spawn;
var ssh = spawn('ssh', ['cloudstudios.ch']);
ssh.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ssh.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ssh.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
I can enter the password in the console, but I can't do anything after that. I get the following console ouput:
stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.
[email protected]'s password:
stdout: Linux v 2.6.32-5-xen-amd64 #1 SMP Wed Jan 12 05:46:49 UTC 2011 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
stderr: stdin: is not a tty
Has someone an idea how I can get this to work?
Thanks!
I'm trying to run a ssh child process in node.js and control it through my program. My code:
var util = require('util');
var spawn = require('child_process').spawn;
var ssh = spawn('ssh', ['cloudstudios.ch']);
ssh.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ssh.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ssh.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
I can enter the password in the console, but I can't do anything after that. I get the following console ouput:
stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.
[email protected]'s password:
stdout: Linux v 2.6.32-5-xen-amd64 #1 SMP Wed Jan 12 05:46:49 UTC 2011 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
stderr: stdin: is not a tty
Has someone an idea how I can get this to work?
Thanks!
Share Improve this question asked Mar 13, 2011 at 22:03 Van CodingVan Coding 24.5k24 gold badges92 silver badges137 bronze badges 1- Check this out github.com/steelbrain/node-ssh – Steel Brain Commented May 23, 2015 at 6:26
2 Answers
Reset to default 10try a little modification:
var ssh = spawn('ssh', ['-tt', 'xxx']);
and:
process.stdin.resume();
process.stdin.on('data', function (chunk) {
ssh.stdin.write(chunk);
});
I´ve created a SSHClient for node.js now. You can download the sourcecode at https://github.com/VanCoding/NodeSSH.
Hope it will help some other people.