当前位置: 代码迷 >> JavaScript >> node.js child_process simple operctor 二
  详细解决方案

node.js child_process simple operctor 二

热度:896   发布时间:2013-11-23 10:52:51.0
node.js child_process simple operctor 2
[node.js] clied_process

simple operctor : ps -ax | grep ssh


var spawn = require('child_process').spawn,
    ps    = spawn('ps', ['ax']),
    grep  = spawn('grep', ['ssh']);

ps.stdout.on('data', function (data) {
    grep.stdin.write(data);
});

ps.stderr.on('data', function (data) {
    console.log('ps stderr: ' + data);
});

ps.on('close', function (code) {
    if (code !== 0) {
        console.log('ps process exited with code ' + code);
    }
    grep.stdin.end();
});

grep.stdout.on('data', function (data) {
    console.log('' + data);
});

grep.stderr.on('data', function (data) {
    console.log('grep stderr: ' + data);
});

grep.on('close', function (code) {
    if (code !== 0) {
        console.log('grep process exited with code ' + code);
    }
});

  相关解决方案