May be duplicate.
I would like to write javascript which can execute linux command in firefox (seems to be impossible but asking w开发者_运维百科ith hope)
from googling, found that it is possible for IE through "ActiveXObject".
here is sample code:
<SCRIPT type="text/javascript" LANGUAGE="JavaScript">
function executeCommands(inputparms)
{
// Instantiate the Shell object and invoke
its execute method.
var oShell = new ActiveXObject("Shell.Application");
var commandtoRun = "C:\\Winnt\\Notepad.exe";
if (inputparms != "")
{
var commandParms = document.Form1.filename.value;
}
// Invoke the execute method.
oShell.ShellExecute(commandtoRun, commandParms,
"", "open", "1");
}
</SCRIPT>
So, Is there any equivalent of ActiveXObject in javascript for mozilla apps? I'm quite new to javascript so please, correct mistakes if any.
Thanks!
In a Firefox add-on you can use nsIProcess. Something along these lines:
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\Winnt\\Notepad.exe");
var process = Components.classes["@mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(file);
process.runAsync(["c:\\file.txt"]);
This API is only accessible to privileged code of course.
No, it's not possible to run arbitrary, native commands on the client's machine.
精彩评论