Spawning process with arguments in node.js

五迷三道 提交于 2019-12-08 14:46:18

问题


I need to spawn a child process from node.js, whilst using ulimit to keep it from using to much memory.

Following the docs, it wasn't hard to get the basic spawn working: child = spawn("coffee", ["app.coffee"]).

However, doing what I do below just makes the spawn die silently.

child = spawn("ulimit", ["-m 65536;", "coffee app.coffee"])

If I would run ulimit -m 65536; coffee app.coffee - it works as intented.

What am I doing wrong here?


回答1:


Those are two different commands. Don't club them if you are using spawn. Use separate child processes.

 child1 = spawn('ulimit', ['-m', '65536']);
 child2 = spawn('coffee', ['app.coffee']);

If you are not interested in output stream(if you want just buffered output) you can use exec.

var exec = require('child_process').exec,
child;

child = exec('ulimit -m 65536; coffee app.coffee',
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
  }
});


来源:https://stackoverflow.com/questions/12778596/spawning-process-with-arguments-in-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!