I’d like to run some command for example:
notepad C:\file.txt
using Firefox addon and nsIProcess. I’ve already written code like bellow:
var exepath = "C:\Windows\System32\cmd.exe";
var args = ["/c", "notepad", "C:\file.txt"];
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(exepath);
var process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
process.init(file);
process.run(true, args, args.length);
But I don’t want opening window. Is it possible to run some command without opening this window?
I know, that I can use cmd.exe /C start notepad to close this window after command executed, but it flashes (appears and disappears). Additionally I’d like to read exit value:
var exitval = process.exitValue;
I forgot to mention that I can’t install any additional software!
You can run Notepad directly – you don’t need
cmd.exefor that. But you have to find the full path of the executable. Its path is%windir%/notepad.exe, you can use nsIEnvironment to resolve that path (something you actually have to do withcmd.exeas well instead of assuming that Windows is installed inc:\windows):And just in case you want to run something other than Notepad: you will have to do the work that the command line is normally doing, namely getting the
PATHenvironment variable and going through the directories in the list, looking where the file exits.