-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (37 loc) · 1.07 KB
/
index.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
const {Observable} = require('rxjs')
const {exec} = require('child_process')
/**
* Devuelve un Observable de un exec de la child_process. Aka system command.
* onNext -> stdout
* onError -> stderr
*
* @param cmdStr
* @param environmentOptions
* @returns {never}
* @constructor
*/
function OOExec (cmdStr, environmentOptions, verbose = true) {
return Observable.create(function (observer) {
exec(cmdStr, environmentOptions, (error, stdout, stderr) => {
if (verbose) {//collaterals but who cares.
console.log('execuing ( ', cmdStr, ' )')
console.log('with Environment Options :', environmentOptions)
console.log('error-->', error)
console.log('stdout-->', stdout)
console.log('stderr-->', stderr)
}
if (error) {
observer.error(stderr)
}
observer.next(stdout)
observer.complete()
})
return {
unsubscribe: function () {
if (verbose) {console.log('completed OOexec :P ', cmdStr) }
},
}
})
}
var module = module || {};//ES5 retro-compatibility
module.exports = OOExec;