summaryrefslogtreecommitdiff
path: root/using_Q/ls-test-2.js
diff options
context:
space:
mode:
authorpepper <pepper@chimecrisis.com>2014-05-06 13:46:24 -0700
committerpepper <pepper@chimecrisis.com>2014-05-06 13:46:24 -0700
commitc552945defe89e3055f2305fe598c5db0f0b8355 (patch)
tree277fcb07642c40d8a04587f110f0466be74a5e32 /using_Q/ls-test-2.js
parent37aa15421f6bbd3a6ce605ee8f9a13bb3bc84c2b (diff)
updated
Diffstat (limited to 'using_Q/ls-test-2.js')
-rw-r--r--using_Q/ls-test-2.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/using_Q/ls-test-2.js b/using_Q/ls-test-2.js
new file mode 100644
index 0000000..df71a72
--- /dev/null
+++ b/using_Q/ls-test-2.js
@@ -0,0 +1,37 @@
+#!/usr/local/bin/node
+Q = require('q');
+var childProcess = require('child_process'), ls;
+function dumper(content){
+ console.log(JSON.stringify(content));
+}
+
+var things = [ "ls | grep \"[^a-z]\"", "ls /", "ls | while read a; do echo \"$a\" | sed s/\./MAMAMIA/g" ];
+
+function get_all_the_things(things) {
+ var the_promises = [];
+
+ things.forEach(function(thing) {
+ var deferred = Q.defer();
+
+ ls = childProcess.exec(thing, function (error, stdout, stderr) {
+ if (error) {
+ // console.log(error.stack);
+ // console.log('Error code: '+error.code);
+ // console.log('Signal received: '+error.signal);
+ }
+ // console.log('Child Process STDOUT: '+stdout);
+ // console.log('Child Process STDERR: '+stderr);
+ });
+
+ ls.on('exit', function (code) {
+ // console.log('Child process exited with exit code '+code);
+ deferred.resolve(code);
+ });
+
+ the_promises.push(deferred.promise);
+ });
+
+ return Q.all(the_promises);
+}
+get_all_the_things(things).then(function(result){ dumper(result) });
+//[0,0,2]