How to kill a tail process that is running with nodejs ssh2?

How do I kill the tail process I am running in this request?

var c = new Ssh2();
   c.on('connect', function() {
     console.log('Connection :: connect');
   });
   c.on('ready', function() {
     console.log('Connection :: ready');
     c.exec('tail -f test.txt', function(err, stream) {
    if (err) throw err;
    stream.on('data', function(data, extended) {
        console.log((extended === 'stderr' ? 'STDERR: ' : '')
                   + data);
    });
    stream.on('exit', function(code, 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: '127.0.0.1',
     port: 22,
     username: 'test',
     password: 'test'
   });

      

Or is there any suggestion to accomplish tail -f

with nodejs?

+3


source to share


1 answer


The easiest way to do this is to use this command line form: 'tail -f test.txt and read; kill $! '.



Then when you want to kill the process, just stream.write('\n');

+2


source







All Articles