aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PursLoader/ChildProcess.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/PursLoader/ChildProcess.js')
-rw-r--r--src/PursLoader/ChildProcess.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/PursLoader/ChildProcess.js b/src/PursLoader/ChildProcess.js
new file mode 100644
index 0000000..d62aef6
--- /dev/null
+++ b/src/PursLoader/ChildProcess.js
@@ -0,0 +1,40 @@
1'use strict';
2
3// module PursLoader.ChildProcess
4
5var child_process = require('child_process');
6
7var chalk = require('chalk');
8
9function spawnFn(command, args, errback, callback) {
10 return function(){
11 var process = child_process.spawn(command, args);
12
13 var stdout = new Buffer(0);
14
15 var stderr = new Buffer(0);
16
17 process.stdout.on('data', function(data){
18 stdout = Buffer.concat([stdout, new Buffer(data)]);
19 });
20
21 process.stderr.on('data', function(data){
22 stderr = Buffer.concat([stderr, new Buffer(data)]);
23 });
24
25 process.on('close', function(code){
26 var output = stdout.toString('utf-8');
27
28 var error = stderr.toString('utf-8');
29
30 if (error.length > 0) {
31 console.error('\n' + chalk.red('*') + ' ' + error);
32 }
33
34 if (code !== 0) errback(new Error('Process terminated with code ' + code))();
35 else callback(output)();
36 });
37 };
38}
39
40exports.spawnFn = spawnFn;