summaryrefslogtreecommitdiff
path: root/using_Q/ls-test-2.js
diff options
context:
space:
mode:
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]