1 module PursLoader.ChildProcess
6 import Control.Monad.Aff (Aff(), makeAff)
7 import Control.Monad.Eff (Eff())
8 import Control.Monad.Eff.Exception (Error())
12 foreign import data ChildProcess :: !
14 spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String
15 spawn command args = makeAff $ runFn4 spawnFn command args
17 foreign import spawnFn """
18 function spawnFn(command, args, errback, callback) {
20 var child_process = require('child_process');
22 var process = child_process.spawn(command, args);
24 var stdout = new Buffer(0);
26 process.stdout.on('data', function(data){
27 stdout = Buffer.concat([stdout, new Buffer(data)]);
30 process.on('close', function(code){
31 if (code !== 0) errback(new Error(stdout.toString()))();
32 else callback(stdout.toString())();
36 """ :: forall eff. Fn4 String
38 (Error -> Eff (cp :: ChildProcess | eff) Unit)
39 (String -> Eff (cp :: ChildProcess | eff) Unit)
40 (Eff (cp :: ChildProcess | eff) Unit)