Santo
Santo

Reputation: 23

How to kill a tail process that's execute using nodejs ssh2?

How to kill tail process that i execute in this query ?

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 execute tail -f using nodejs?

Upvotes: 2

Views: 1392

Answers (1)

mscdex
mscdex

Reputation: 106746

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

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

Upvotes: 3

Related Questions