9

I'm using MeteorJS.

I'd like to call a bash command from the javascript server side. This seems possible with nodeJS: http://www.dzone.com/snippets/execute-unix-command-nodejs

However, I can't find something similar with meteorJS. I'd like something like that :

if(Meteor.isServer){
...

exec("myCommand");
}
nha
  • 16,863
  • 11
  • 86
  • 120

2 Answers2

9

You can also use child_process.spawn().

Read More about executing a UNIX command with Meteor.

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);
});
Julien Le Coupanec
  • 7,195
  • 6
  • 47
  • 60
5

If you take the calls to require from the sample and prefix them with

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

it should work.

David Wihl
  • 1,471
  • 13
  • 14