Child_process.spawn to meteor

Has anyone had any success using node childprocess.spawn () on meteor on any platform? I tried it for both OS X and Windows as follows and the app crashes immediately:

if (Meteor.isServer) {
  Meteor.startup(function() {
    cmd = __meteor_bootstrap__.require('child_process').spawn('irb', [], {detached: true, stdio:'pipe'});
    cmd.stdout.on('data', function(data){
      Fiber(function(){
        Replies.remove({});
        Replies.insert({message: data});
      }).run();
    });

 });
}

      

In the console I get the following OS X message and similar on Windows:

Assertion failed: (handle->InternalFieldCount() > 0), function Unwrap, file ../src/node_object_wrap.h, line 61.
Exited from signal: SIGABRT

      

Does anyone have any thoughts?

Thank!
Greg

+3


source to share


1 answer


data

- node Buffer , which cannot be inserted into the collection; convert it to string first.

Also note that your data event callback will be called multiple times as the data is streamed from the child process (unless the output is small enough that you can get it all in one buffer). You will need to accumulate data in a buffer and then insert it into your collection when you receive the end of stream event.



If there is a chance that your child process will output utf-8 (nothing but pure ASCII), be sure to copy the data in the node buffer first, and then convert the entire buffer to a string, rather than convert each piece of data to a string and accumulate the data as strings. (utf-8 characters can span multiple bytes, so you cannot slice the byte stream into arbitrary chunks and parse each part as utf-8 separately).

+1


source







All Articles