]> git.immae.eu Git - github/fretlink/purs-loader.git/blame - src/ChildProcess.purs
Bumping version number to 0.3.0
[github/fretlink/purs-loader.git] / src / ChildProcess.purs
CommitLineData
c194f84c 1module PursLoader.ChildProcess
2 ( ChildProcess()
3 , spawn
4 ) where
5
6import Control.Monad.Aff (Aff(), makeAff)
7import Control.Monad.Eff (Eff())
8import Control.Monad.Eff.Exception (Error())
9
10import Data.Function
11
12foreign import data ChildProcess :: !
13
14spawn :: forall eff. String -> [String] -> Aff (cp :: ChildProcess | eff) String
15spawn command args = makeAff $ runFn4 spawnFn command args
16
17foreign import spawnFn """
18function spawnFn(command, args, errback, callback) {
19 return function(){
20 var child_process = require('child_process');
21
22 var process = child_process.spawn(command, args);
23
24 var stdout = new Buffer(0);
25
26 process.stdout.on('data', function(data){
27 stdout = Buffer.concat([stdout, new Buffer(data)]);
28 });
29
30 process.on('close', function(code){
31 if (code !== 0) errback(new Error(stdout.toString()))();
32 else callback(stdout.toString())();
33 });
34 };
35}
36""" :: forall eff. Fn4 String
37 [String]
38 (Error -> Eff (cp :: ChildProcess | eff) Unit)
39 (String -> Eff (cp :: ChildProcess | eff) Unit)
40 (Eff (cp :: ChildProcess | eff) Unit)