-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
spawn.js
39 lines (33 loc) · 986 Bytes
/
spawn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var spawn = require('child_process').spawn;
/**
* Launches a new process.
*
* @method spawn
* @param {Object} options
* @param {String} options.command The command to run
* @param {Array} options.args The list of string arguments
* @param {Object} [options.options] See [child_process.spawn](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
* @for util
*/
module.exports = function(options){
var comm = spawn(options.command, options.args, options.options);
comm.stdout.setEncoding('utf8');
comm.stderr.setEncoding('utf8');
if (options.stdout){
comm.stdout.on('data', options.stdout);
} else {
comm.stdout.on('data', function(data){
process.stdout.write(data);
});
}
if (options.stderr){
comm.stderr.on('data', options.stderr);
} else {
comm.stderr.on('data', function(data){
process.stderr.write(data);
});
}
if (options.exit){
comm.on('exit', options.exit);
}
};