Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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

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

Problem

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?

Problem courtesy of: Santo

Solution

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');

Solution courtesy of: mscdex

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

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

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×