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
  • 17,623
  • 13
  • 87
  • 133

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,742
  • 9
  • 53
  • 67
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,491
  • 13
  • 14