NsIProcess: Difference between revisions

Jump to navigation Jump to search
959 bytes removed ,  6 July 2009
no edit summary
No edit summary
No edit summary
 
Line 9: Line 9:
Components.utils.import("resource://gre/Process.jsm");
Components.utils.import("resource://gre/Process.jsm");


// Note: this only create the process object: the new process isn't actually
function callback(evt) {
// launched until .run() is called
  // do stuff
var p = new Process("c:\\myapp.exe");
}


// Set up stdin of the process
var p = new Process(["appdir/myapp", "someargs],
p.setstdin(null); // the default value: inherit stdin from the current process
                    {cwd: "ProfD", charset: "utf8"},
                    callback);
p.start();


// open the file and use that as stdin of the new process
// or without callback
p.setstdin(new Process.InputFile("c:\\myinput.txt"));


// set up a writable pipe to send data to the new process
var p = new Process(["appdir/myapp", "someargs],  
// later, you can write to the pipe using stdin.write(data)
                    {cwd: "ProfD", charset: "utf8"});
// the writing is asynchronous...
p.start();
// if buffers are full, the write() call may throw an exception
let stdin = new Process.WritePipe();
p.setstdin(stdin);


// Set up stdout/stderr of the process
var ret = p.communicate("something");
p.setstdout(null); // the default value: inherit stdin from the current process
 
// open the file and use that as stdout of the new process
p.setstdout(new Process.OutputFile("c:\\myoutput.txt"));
 
// capture output and processes it via a callback
let stdout = new Process.ReadPipe();
p.setstdout(stdout);
stdout.addEventListener("dataReceived", function(d) {
alert("Got data from child process: " + d);
});
 
// Add a callback to get the result code of running the process
p.addCallback("processCompleted", function(r) {
alert("Child process finished with result: " + r);
});
 
// Launch the process
p.run(["argument1", "argument2"]);
</pre>
</pre>
</code>
</code>
210

edits

Navigation menu