NsIProcess: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
=nsIProcess API Proposal=
=nsIProcess2 API Proposal=


=First draft API Proposal=
Project page: [http://zenit.senecac.on.ca/wiki/index.php/User:Jamesboston/nsIProcess Fixing nsIProcess]


Although code will be written in standard XPCOM, the first draft proposal only describes how the API will look from javascript.
===JS API===
 
===Sample Usage===


<code>
<code>
<pre>
<pre>
// first argument is the executable
Components.utils.import("resource://gre/Process.jsm");
var arguments = ["argument1", "argument2"];


// create nsIProcess
function callback(evt) {
var process = Components.classes["@mozilla.org/process/util;1"]
  // do stuff
                        .createInstance(Components.interfaces.nsIProcess);
}


// start the executable
var p = new Process(["appdir/myapp", "someargs],
process.open(arguments, arguments.length)
                    {cwd: "ProfD", charset: "utf8"},
                    callback);
p.start();


// alternatively it could be opened with interprocess communication
// or without callback
process.open(arguments, arguments.length, stdin, stdout, stderr)
// stdin - callback
// stdout - callback
// stderr - callback


// check if the executable is still running
var p = new Process(["appdir/myapp", "someargs],
process.isRunning()
                    {cwd: "ProfD", charset: "utf8"});
p.start();


// stop the process
var ret = p.communicate("something");
process.close()
</pre>
</pre>
</code>
</code>


=Reference=
=== Underlying XPCOM interfaces ===


Project page: [http://zenit.senecac.on.ca/wiki/index.php/User:Jamesboston/nsIProcess Fixing nsIProcess]
<code>
<pre>
interface nsIProcess2 : public nsISupports
{
void init(in nsIFile program);
 
void inheritStdin();
void pipeStdin(in nsIPOSIXOutputStream);
 
void inheritStdout();
void fileStdout(in nsIFile);
void pipeStdout(in nsIPOSIXInputStream);
 
void inheritStderr();
void fileStderr(in nsIFile);
void pipeStderr(in nsIPOSIXInputStream);
 
readonly attribute unsigned long result;
readonly attribute unsigned long pid;
attribute nsIObserver listener;
 
void run([array, size_is(argv)] in wstring argv, in unsigned long argc);
};
 
interface nsIPOSIXOutputStream : public nsIOutputStream
{
/* the native POSIX file descriptor for this stream */
readonly attribute unsigned long fd;
};
 
interface nsIPOSIXInputStream : public nsIInputStream
{
/* the native POSIX file descriptor for this stream */
readonly attribute unsigned long fd;
};
 
interface nsIPipeManager : public nsISupports
{
nsIPOSIXInputStream createIncomingPipe();
nsIPOSIXOutputStream createOutgoingPipe();
 
nsIPOSIXInputStream readFile(in nsILocalFile file);
nsIPOSIXOutputStream writeFile(in nsILocalFile file);
};
 
</pre>
</code>

Latest revision as of 17:29, 6 July 2009

nsIProcess2 API Proposal

Project page: Fixing nsIProcess

JS API

Components.utils.import("resource://gre/Process.jsm");

function callback(evt) {
   // do stuff
}

var p = new Process(["appdir/myapp", "someargs], 
                    {cwd: "ProfD", charset: "utf8"},
                    callback);
p.start();

// or without callback

var p = new Process(["appdir/myapp", "someargs], 
                    {cwd: "ProfD", charset: "utf8"});
p.start();

var ret = p.communicate("something");

Underlying XPCOM interfaces

interface nsIProcess2 : public nsISupports
{
 void init(in nsIFile program);

 void inheritStdin();
 void pipeStdin(in nsIPOSIXOutputStream);

 void inheritStdout();
 void fileStdout(in nsIFile);
 void pipeStdout(in nsIPOSIXInputStream);

 void inheritStderr();
 void fileStderr(in nsIFile);
 void pipeStderr(in nsIPOSIXInputStream);

 readonly attribute unsigned long result;
 readonly attribute unsigned long pid;
 attribute nsIObserver listener;

 void run([array, size_is(argv)] in wstring argv, in unsigned long argc);
};

interface nsIPOSIXOutputStream : public nsIOutputStream
{
 /* the native POSIX file descriptor for this stream */
 readonly attribute unsigned long fd;
};

interface nsIPOSIXInputStream : public nsIInputStream
{
 /* the native POSIX file descriptor for this stream */
 readonly attribute unsigned long fd;
};

interface nsIPipeManager : public nsISupports
{
 nsIPOSIXInputStream createIncomingPipe();
 nsIPOSIXOutputStream createOutgoingPipe();

 nsIPOSIXInputStream readFile(in nsILocalFile file);
 nsIPOSIXOutputStream writeFile(in nsILocalFile file);
};