Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arlando/4eea2b56640e59bdf20a to your computer and use it in GitHub Desktop.
Save arlando/4eea2b56640e59bdf20a to your computer and use it in GitHub Desktop.
var
Connection = require('../lib/Connection');
var c = new Connection();
c.on('connect', function() {
console.log('Connection :: connect');
});
c.on('ready', function() {
var promptDataCallCount = 0;
console.log('Connection :: ready');
c.shell(function(err, stream) {
if (err) throw err;
stream.on('data', function(data, extended) {
console.log((extended === 'stderr' ? 'STDERR: ' : 'STDOUT: ')
+ data.toString());
if (promptDataCallCount === 1) {
stream.write('uptime\n');
}
promptDataCallCount++;
});
stream.on('end', function() {
console.log('Stream :: EOF');
});
stream.on('close', function() {
console.log('Stream :: close');
});
stream.on('exit', function(code, signal) {
console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
c.end();
});
});
});
c.on('error', function(err) {
console.log('Connection :: error :: ' + err);
});
c.on('end', function() {
console.log('Connection :: end');
});
c.on('close', function(had_error) {
console.log('Connection :: close');
});
c.connect({
host: 'localhost',
username: 'foo',
password: 'bar'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment