Running applications

From MozillaZine Knowledge Base

(Difference between revisions)
Revision as of 01:58, 27 November 2004
Asqueella (Talk | contribs)

<-- Previous diff
Revision as of 02:05, 27 November 2004
Asqueella (Talk | contribs)
Next diff -->
Line 27: Line 27:
// to the process. // to the process.
var args = ["argument1", "argument2"]; var args = ["argument1", "argument2"];, args, args.legnth());</pre>, args, args.length());</pre>
==References== ==References==
*[ nsILocalFile interface] *[ nsILocalFile interface]
*[ nsIProcess interface] *[ nsIProcess interface]

Revision as of 02:05, 27 November 2004


Runing programs

This page describes how to run other programs from your JavaScript code, using Mozilla XPCOM interfaces.

There are two ways to run external programs. The first is to use nsILocalFile::launch() method, the second is to use nsIProcess interface.


This method has the same effect as if you double clicked the file, so for executable files, it will just run the file without any parameters. It may not be implemented on some platforms, so make sure your this method is implemented on your target platforms. It seems to be implemented on Windows.

For more information on nsIFile/nsILocalFile, see File IO.


The recommended way is to use nsIProcess interface. It is as easy as:

// create an nsILocalFile for the executable
var file = Components.classes[";1"]

// create an nsIProcess
var process = Components.classes[";1"]

// 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 = ["argument1", "argument2"];, args, args.length());