3

如何杀死我在此查询中执行的尾部进程?

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

或者有什么建议tail -f使用nodejs执行?

4

1 回答 1

2

最简单的方法是在命令行中使用这样的形式:'tail -f test.txt & read; 杀死$!'。

然后当你想杀死进程时,只需stream.write('\n');

于 2013-02-07T11:05:53.950 回答