Commits

portix committed 9aad00a

Return a new Deferred from system.spawn

  • Participants
  • Parent commits b1d10c8

Comments (0)

Files changed (1)

File scripts/lib/system.js

             value : (function() {
                 return function(command, onStdout, onStderr, stdin, environ) {
                     var stdout, stderr;
-                    return system._spawn(command, 
-                                !onStdout ? null : function(response) {
-                                    var ret;
-                                    stdout = onStdout.call(onStdout, response) || response;
-                                }, 
-                                !onStderr ? null : function(response) {
-                                    var ret;
-                                    stderr = onStderr.call(onStderr, response) || response;
-                                    return ret;
-                                }, 
-                                stdin, environ).then(
-                                    function() { return stdout; }, 
-                                    function() { return stdin; }
-                                );
+                    var d = new Deferred();
+                    system._spawn(command, 
+                        function(response) {
+                            stdout = onStdout ? (onStdout.call(onStdout, response) || response) : response;
+                        },  
+                        onStderr || function(response) {
+                            stderr = onStderr ? (onStderr.call(onStderr, response) || response) : response;
+                        }, 
+                        stdin, environ).then(
+                            function() { return d.resolve(stdout); }, 
+                            function(status) { return d.reject({ status : status, stderr : stderr }, stderr); }
+                        );
+                    return d;
                 };
             })()
         }