[英]Node ssh2 sends multiple data events for a simple ls command
I am trying to do a simple 'ls' using node ssh connection on localhost. 我正在尝试在本地主机上使用节点ssh连接做一个简单的'ls'。 The code is like this, 代码是这样的,
var Connection = require('ssh2');
var conn = new Connection();
conn.on('ready', function() {
conn.shell('uptime', function(err, stream) {
if (err) throw err;
stream.on('data', function(data) {
console.log('STDOUT: ' + data);
});
stream.end('ls');
});
}).connect({
host: '127.0.0.1',
port: 22,
username: '*****',
password: '*****'
});
And i am getting multiple data events, with the output like this, 我收到多个数据事件,输出如下:
STDOUT: Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-24-generic x86_64)
* Documentation: https://help.ubuntu.com/
STDOUT:
Last login: Sun Dec 28 09:28:21 2014 from localhost
STDOUT: ls
STDOUT: sk@sk-box:~$ l
STDOUT: s
what am i doing wrong here? 我在这里做错了什么?
Append newline character after ls
command. 在ls
命令后附加换行符。
var Connection = require('ssh2');
var conn = new Connection();
conn.on('ready', function() {
conn.shell('uptime', function(err, stream) {
if (err) throw err;
stream.on('data', function(data) {
console.log('STDOUT: ' + data);
});
stream.end('ls\n');
});
}).connect({
host: '127.0.0.1',
port: 22,
username: '*****',
password: '*****'
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.