How to execute windows command from Firefox add-on?

How to execute windows command and display it using Firefox?

For example: ping www.stackoverfow.com

I'm just trying to learn more about developing firefox add-ons by executing a binary (or) executable file packaged together, or by running the windows command.

+5
source share
1 answer

For this you would use nsIProcess . In your case, everything is complicated by the fact that you don’t know which application you want to run - usually it will c:\windows\system32\ping.exe, but you cannot be sure. If you do not want to analyze the environment variable yourself PATH, you can make a command line shell for it:

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

var env = Components.classes["@mozilla.org/process/environment;1"]
                    .getService(Components.interfaces.nsIEnvironment);
var shell = new FileUtils.File(env.get("COMSPEC"));
var args = ["/c", "ping stackoverflow.org"];

var process = Components.classes["@mozilla.org/process/util;1"]
                        .createInstance(Components.interfaces.nsIProcess);
process.init(shell);
process.runAsync(args, args.length);

: COMSPEC , nsIEnvironment.

, , , , , . , ( ping stackoverflow.org > c:\\temp\\foo.txt ) .

+12

All Articles