(function() { var system = namespace("system"); Object.defineProperties(system, { "spawn" : { value : (function() { return function(command, detail) { detail = detail || {}; var onStdout = null, onStderr = null; var d = new Deferred(); var result = { status : 0 }; if (detail.cacheStdout || detail.onStdout) { result.stdout = ""; onStdout = function(response) { result.stdout += response; if (detail.onStdout) { response.split("\n").forEach(function(line) { detail.onStdout(line); }); } }; } if (detail.cacheStderr || detail.onStderr) { result.stderr = ""; onStderr = function(response) { result.stderr += response; if (detail.onStderr) { response.split("\n").forEach(function(line) { detail.onStderr(line); }); } }; } system._spawn(command, onStdout, onStderr, detail.stdin, detail.environment).then( function(status) { result.status = status; if (detail.onFinished) { detail.onFinished(result); } d.resolve(result); }, function(status) { result.status = status; if (detail.onFinished) { detail.onFinished(result); } d.reject(result); } ); return d; }; })() } }); Object.freeze(system); })(); 