diff --git a/README.md b/README.md index b5aae7a..20c45b4 100644 --- a/README.md +++ b/README.md @@ -13,20 +13,20 @@ and in our case, from addon-sdk libraries :) arguments: ['$@', '$ENV_TEST'], environment: ['ENV_TEST=OK'], - stdin: subprocess.WritablePipe(function() { - this.write("stdin"); - this.close(); - }), - stdout: subprocess.ReadablePipe(function(data) { + stdin: function(stdin) { + stdin.write("stdin"); + stdin.close(); + }, + stdout: function(data) { // data should be equal to: "stdin OK" - }), - stderr: subprocess.ReadablePipe(function(data) { + }, + stderr: function(data) { - }), - onFinished: subprocess.Terminate(function() { - - }), + }, + done: function(result) { + console.log("process terminated with " + result.exitCode + "\n"); + }, mergeStderr: false }); diff --git a/lib/subprocess.js b/lib/subprocess.js index 4ac9abe..8067a7d 100644 --- a/lib/subprocess.js +++ b/lib/subprocess.js @@ -333,7 +333,8 @@ function getPlatformValue(valueType) { var gDebugFunc = null, gLogFunc = null, - gXulRuntime = null; + gXulRuntime = null, + wrap = function (obj) {return obj;}; function LogError(s) { if (gLogFunc) @@ -464,6 +465,9 @@ var subprocess = { }, registerLogHandler: function(func) { gLogFunc = func; + }, + addWrapper: function (userWrapper) { + wrap = userWrapper; } }; @@ -1022,11 +1026,11 @@ function subprocess_win32(options) { setTimeout(function _done() { if (options.done) { try { - options.done({ + options.done(wrap({ exitCode: exitCode, stdout: output, stderr: error, - }); + })); } catch (ex) { // prevent from blocking if options.done() throws an error @@ -1053,14 +1057,14 @@ function subprocess_win32(options) { if(typeof(options.stdin) == 'function') { try { - options.stdin({ + options.stdin(wrap({ write: function(data) { writeStdin(data); }, close: function() { closeStdinHandle(); } - }); + })); } catch (ex) { // prevent from failing if options.stdin() throws an exception @@ -1611,11 +1615,11 @@ function subprocess_unix(options) { setTimeout(function _done() { if (options.done) { try { - options.done({ + options.done(wrap({ exitCode: exitCode, stdout: output, stderr: error, - }); + })); } catch(ex) { // prevent from blocking if options.done() throws an error @@ -1647,14 +1651,14 @@ function subprocess_unix(options) { createStdinWriter(); if(typeof(options.stdin) == 'function') { try { - options.stdin({ + options.stdin(wrap({ write: function(data) { writeStdin(data); }, close: function() { closeStdinHandle(); } - }); + })); } catch(ex) { // prevent from failing if options.stdin() throws an exception