Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

meteorJS call a shell command from the server

Tags:

shell

meteor

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");
}
like image 329
nha Avatar asked Dec 08 '12 22:12

nha


2 Answers

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);
});
like image 117
Julien Le Coupanec Avatar answered Nov 05 '22 20:11

Julien Le Coupanec


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

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

it should work.

like image 36
David Wihl Avatar answered Nov 05 '22 21:11

David Wihl