1

This is my first Meteor application, I'm really excited to try to learn the framework, so I just built an internal website that will manage a bunch of command line processes. Many of these command line processes take 10-20 minutes to execute, so I was hoping I could deliver feedback to the user during execution, such as piping the stdout back to the user as the process executed. Right now I'm doing this:

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

Meteor.methods({
  foo: function(job_id) {
    var select = { _id: job_id };
    var execCommand = "dir /s"; // or whatever it is I'm doing
    exec(execCommand, function(error, stdout, stderr) {
      Fiber (function() {
        Jobs.update(select, {$set: { logs: stdout }});
      }).run();
    })
  }
});

This works fine, and when the job completes I see the log, but I was wondering if there was a better way I could do it so that as results are available I can start sending them. Any advise is welcome.

Dio
  • 660
  • 1
  • 9
  • 19

1 Answers1

1

I would append the output line by line using the MongoDB $push operator instead of resetting the content of "logs" every time. That will save you some bandwidth I guess.

But apart from that, exec does not call your function regulary. Take a look at the "node.js execute system command synchronously question for a workaround.

Community
  • 1
  • 1
Marcus Riemer
  • 7,244
  • 8
  • 51
  • 76