b2g/simulator/packages/subprocess/README.md

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <h2>What's that?</h2>
michael@0 2 Simply package enigmail hard work on providing IPC feature in mozilla platform.
michael@0 3 So we are able to launch child proccesses from javascript,
michael@0 4 and in our case, from addon-sdk libraries :)
michael@0 5
michael@0 6 <h2>Sample of code:</h2>
michael@0 7 This object allows to start a process, and read/write data to/from it
michael@0 8 using stdin/stdout/stderr streams.
michael@0 9 Usage example:
michael@0 10
michael@0 11 const subprocess = require("subprocess");
michael@0 12 var p = subprocess.call({
michael@0 13 command: '/bin/foo',
michael@0 14 arguments: ['-v', 'foo'],
michael@0 15 environment: [ "XYZ=abc", "MYVAR=def" ],
michael@0 16 charset: 'UTF-8',
michael@0 17 workdir: '/home/foo',
michael@0 18 //stdin: "some value to write to stdin\nfoobar",
michael@0 19 stdin: function(stdin) {
michael@0 20 stdin.write("some value to write to stdin\nfoobar");
michael@0 21 stdin.close();
michael@0 22 },
michael@0 23 stdout: function(data) {
michael@0 24 dump("got data on stdout:" + data + "\n");
michael@0 25 },
michael@0 26 stderr: function(data) {
michael@0 27 dump("got data on stderr:" + data + "\n");
michael@0 28 },
michael@0 29 done: function(result) {
michael@0 30 dump("process terminated with " + result.exitCode + "\n");
michael@0 31 },
michael@0 32 mergeStderr: false
michael@0 33 });
michael@0 34 p.wait(); // wait for the subprocess to terminate
michael@0 35 // this will block the main thread,
michael@0 36 // only do if you can wait that long
michael@0 37
michael@0 38
michael@0 39 Description of parameters:
michael@0 40 --------------------------
michael@0 41 Apart from <command>, all arguments are optional.
michael@0 42
michael@0 43 command: either a |nsIFile| object pointing to an executable file or a
michael@0 44 String containing the platform-dependent path to an executable
michael@0 45 file.
michael@0 46
michael@0 47 arguments: optional string array containing the arguments to the command.
michael@0 48
michael@0 49 environment: optional string array containing environment variables to pass
michael@0 50 to the command. The array elements must have the form
michael@0 51 "VAR=data". Please note that if environment is defined, it
michael@0 52 replaces any existing environment variables for the subprocess.
michael@0 53
michael@0 54 charset: Output is decoded with given charset and a string is returned.
michael@0 55 If charset is undefined, "UTF-8" is used as default.
michael@0 56 To get binary data, set this to null and the returned string
michael@0 57 is not decoded in any way.
michael@0 58
michael@0 59 workdir: optional; String containing the platform-dependent path to a
michael@0 60 directory to become the current working directory of the subprocess.
michael@0 61
michael@0 62 stdin: optional input data for the process to be passed on standard
michael@0 63 input. stdin can either be a string or a function.
michael@0 64 A |string| gets written to stdin and stdin gets closed;
michael@0 65 A |function| gets passed an object with write and close function.
michael@0 66 Please note that the write() function will return almost immediately;
michael@0 67 data is always written asynchronously on a separate thread.
michael@0 68
michael@0 69 stdout: an optional function that can receive output data from the
michael@0 70 process. The stdout-function is called asynchronously; it can be
michael@0 71 called mutliple times during the execution of a process.
michael@0 72 At a minimum at each occurance of \n or \r.
michael@0 73 Please note that null-characters might need to be escaped
michael@0 74 with something like 'data.replace(/\0/g, "\\0");'.
michael@0 75
michael@0 76 stderr: an optional function that can receive stderr data from the
michael@0 77 process. The stderr-function is called asynchronously; it can be
michael@0 78 called mutliple times during the execution of a process. Please
michael@0 79 note that null-characters might need to be escaped with
michael@0 80 something like 'data.replace(/\0/g, "\\0");'.
michael@0 81 (on windows it only gets called once right now)
michael@0 82
michael@0 83 done: optional function that is called when the process has terminated.
michael@0 84 The exit code from the process available via result.exitCode. If
michael@0 85 stdout is not defined, then the output from stdout is available
michael@0 86 via result.stdout. stderr data is in result.stderr
michael@0 87
michael@0 88 mergeStderr: optional boolean value. If true, stderr is merged with stdout;
michael@0 89 no data will be provided to stderr.
michael@0 90
michael@0 91
michael@0 92 Description of object returned by subprocess.call(...)
michael@0 93 ------------------------------------------------------
michael@0 94 The object returned by subprocess.call offers a few methods that can be
michael@0 95 executed:
michael@0 96
michael@0 97 wait(): waits for the subprocess to terminate. It is not required to use
michael@0 98 wait; done will be called in any case when the subprocess terminated.
michael@0 99
michael@0 100 kill(hardKill): kill the subprocess. Any open pipes will be closed and
michael@0 101 done will be called.
michael@0 102 hardKill [ignored on Windows]:
michael@0 103 - false: signal the process terminate (SIGTERM)
michael@0 104 - true: kill the process (SIGKILL)
michael@0 105
michael@0 106
michael@0 107 Other methods in subprocess
michael@0 108 ---------------------------
michael@0 109
michael@0 110 registerDebugHandler(functionRef): register a handler that is called to get
michael@0 111 debugging information
michael@0 112 registerLogHandler(functionRef): register a handler that is called to get error
michael@0 113 messages
michael@0 114
michael@0 115 example:
michael@0 116 subprocess.registerLogHandler( function(s) { dump(s); } );
michael@0 117
michael@0 118
michael@0 119 <h2>Credits:</h2>
michael@0 120 All enigmail team working on IPC component.
michael@0 121 The Initial Developer of this code is Jan Gerber.
michael@0 122 Portions created by Jan Gerber <j@mailb.org>,
michael@0 123 Patrick Brunschwig (author of almost all code) <patrick@mozilla-enigmail.org>,
michael@0 124 Ramalingam Saravanan (from enigmail team) <svn@xmlterm.org>

mercurial