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.

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

mercurial