[Project_owners] getting output from external process

Patrick Brunschwig patrick.brunschwig at gmx.net
Wed Mar 16 12:52:31 EST 2005

Stan James wrote:
> Hi all,
> Is there a simple way to get the output of an external process? When I
> run (for example) SQLite using nsIProcess, the results scroll by in the
> console window, but I can't figure out how to grab them in my extension
> code. I also tried doing a stdout redirect (and read the output file
> after the process terminates), but output still goes to the console and
> no output file is created.
> Here's the code: (Mostly taken from
> http://kb.mozillazine.org/Dev_:_Extensions_:_Example_Code_:_Run_programs)
>    // create an nsILocalFile for the executable
>    var file = Components.classes["@mozilla.org/file/local;1"]
> .createInstance(Components.interfaces.nsILocalFile);
>    file.initWithPath("c:\\temp\\sqlite3.exe");
>    // create an nsIProcess
>    var process = Components.classes["@mozilla.org/process/util;1"]
> .createInstance(Components.interfaces.nsIProcess);
>    process.init(file);
>    // Run the process.
>    // If first param is true, calling process will be blocked until
>    // called process terminates.
>    // Second and third params are used to pass command-line arguments
>    // to the process.
>    var args = ["C:\\temp\\test", "select * from tblReports;",
> ">C:\\temp\\out.txt"];
>    //var args = ["C:\\temp\\test", "select * from tblReports;",
> ">","C:\\temp\\out.txt"];
>    process.run(true, args, args.length);
> Can I grab stdout from JavaScript? Is there another way to redirect
> output from the process?
> Thanks for any tips!

I don't think that there is a standard way in Mozilla. However, you can
use the ipc (pipe) library that was orignially developped for Protozilla
and is now used in Enigmail.


More information about the Project_owners mailing list