9

我正在使用 MeteorJS。

我想从 javascript 服务器端调用 bash 命令。这似乎可以用 nodeJS: http ://www.dzone.com/snippets/execute-unix-command-nodejs

但是,我找不到与 meteorJS 类似的东西。我想要这样的东西:

if(Meteor.isServer){
...

exec("myCommand");
}
4

2 回答 2

9

您也可以使用 child_process.spawn()。

阅读有关使用 Meteor 执行 UNIX 命令的更多信息

spawn = Npm.require('child_process').spawn;

command = spawn('ls', ['-la']);

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

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

command.on('exit', function (code) {
  console.log('child process exited with code ' + code);
});
于 2014-08-14T11:57:48.033 回答
5

如果您从示例中调用 require 并在它们前面加上

var sys = __meteor_bootstrap__.require('sys');

它应该工作。

于 2012-12-09T10:15:12.647 回答