0

**I want to kill the process of the 'trai' command without closing the putty/command prompt OR how can I run the same command in background process OR where to pass 'CTRL+C' command in this code so that it will exitthe command **

var Client = require('ssh2').Client;
var conn = new Client();
conn.on('ready', function() {
  console.log('Client :: ready');
  conn.exec('trai', function(err, stream) {
    if (err) throw err;
    stream.on('close', function(code, signal) {
      console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
      conn.end();
    }).on('data', function(data) {
      console.log('STDOUT: ' + data);
    }).stderr.on('data', function(data) {
      console.log('STDERR: ' + data);
    });
  });
}).connect({
  host: '***.***.***.',
  port: 22,
  username: 'frylock',
  password: 'frylock'
});

As I am new to NodeJS please help me if i am wrong .

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
node mail
  • 1
  • 1
  • 2

1 Answers1

0

You should be able to forcefully close the exec() stream with stream.close(), or if you start your command(s) with a pseudo-tty (passing the pty: true option to exec()) you should be able to send a ctrl-c with stream.end('\x03').

mscdex
  • 104,356
  • 15
  • 192
  • 153