13

node.js で ssh 子プロセスを実行し、プログラムで制御しようとしています。私のコード:

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);
});

コンソールにパスワードを入力することはできますが、その後は何もできません。次のコンソール出力が得られます。

stderr: Pseudo-terminal will not be allocated because stdin is not a terminal.

root@xxxxxxxxxxxxx.xx'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

どうすればこれを機能させることができるか考えている人はいますか?

ありがとう!

4

2 に答える 2

11

少し変更してみてください:

var ssh = spawn('ssh', ['-tt', 'xxx']);

と:

process.stdin.resume();
process.stdin.on('data', function (chunk) {
  ssh.stdin.write(chunk);
});
于 2011-03-13T22:24:36.517 に答える
8

node.js 用の SSHClient を作成しました。ソースコードはhttps://github.com/VanCoding/NodeSSHからダウンロードできます。

それが他の人々を助けることを願っています。

于 2011-03-16T17:25:59.127 に答える