Nodejs exec 와 spawn 의 차이

1989 단어
spawn
child_process.spaen       stdout stderr    。     stdout          Node.js   。
stdout  ’data’,’end’           。              Node ,       ,      
   ,     spawn  
child_process.spawn   “      ”,            ,                   Node

  
var cp = require('child_process');
  //spawn
  var ls = cp.spawn('ls'/*command*/, ['-lh', '/usr']/*args*/, {}/*options, [optional]*/);
  ls.stdout.on('data', function (data) {
    console.log('stdout: ' + data);
  });

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

  ls.on('exit', function (code) {
    console.log('child process exited with code ' + code);
  });

exec
child_process.exec   “      ”,     exec    ,                         buffer  。
exec buffer , “maxBuffer exceeded” child_process.exec buffer。 , buffer 200k。
200k, , “Error:maxBuffer exceeded”。
exec buffer , , exec 。
, spawn 。 exec ? ,
var cp = require('child_process');

  var ls = cp.exec('ls -lh /usr', {}/*options, [optional]*/);

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

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

  ls.on('exit', function (code) {
    console.log('child process exited with code ' + code);
  });

전환 하 다 http://yijiebuyi.com/blog/3ec57c3c46170789eed1aa73792d99e5.html

좋은 웹페이지 즐겨찾기