Running applications: Difference between revisions
m (recategorizing) |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{extdev}} | {{extdev}} | ||
This page describes how to run other programs from your chrome Javascript code, using Mozilla XPCOM interfaces. | |||
This page describes how to run other programs from your | |||
There are two ways to run | There are two ways to run programs. The first is to use <code>[http://xulplanet.com/references/xpcomref/ifaces/nsILocalFile.html nsILocalFile.launch()]</code> method, the second is to use <code>[http://xulplanet.com/references/xpcomref/ifaces/nsIProcess.html nsIProcess]</code> interface. | ||
== | ==Using nsILocalFile.launch()== | ||
This method has the same effect as if you double clicked the file, so for executable files | 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 [[Dev : Extensions : Example Code : File IO | File IO]]. | For more information on <code>nsIFile</code>/<code>nsILocalFile</code>, see [[Dev : Extensions : Example Code : File IO | File IO]]. | ||
== | ==Using nsIProcess== | ||
The recommended way is to use [http://xulplanet.com/references/xpcomref/ifaces/nsIProcess.html nsIProcess] interface. It is as easy as: | The recommended way is to use [http://xulplanet.com/references/xpcomref/ifaces/nsIProcess.html nsIProcess] interface. It is as easy as: | ||
<pre>// create an nsILocalFile for the executable | <pre>// create an nsILocalFile for the executable | ||
Line 35: | Line 34: | ||
*[http://xulplanet.com/references/xpcomref/ifaces/nsIProcess.html nsIProcess interface] | *[http://xulplanet.com/references/xpcomref/ifaces/nsIProcess.html nsIProcess interface] | ||
[[Category:Example code | [[Category:Example code]] [[Category:XPCOM example code]] [[Category:Javascript example code]] |
Revision as of 00:55, 6 March 2005
This page is part of the extension development documentation project.
Ask your questions in MozillaZine Forums. Also try browsing example code.
Note: development documentation is in process of being moved to Mozilla Development Center (MDC).
This page describes how to run other programs from your chrome Javascript code, using Mozilla XPCOM interfaces.
There are two ways to run programs. The first is to use nsILocalFile.launch()
method, the second is to use nsIProcess
interface.
Using nsILocalFile.launch()
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.
Using nsIProcess
The recommended way is to use nsIProcess interface. It is as easy as:
// create an nsILocalFile for the executable var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath("c:\\myapp.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 = ["argument1", "argument2"]; process.run(false, args, args.length);