javascript - 使用javascript在firefox浏览器中评估系统命令或python脚本

标签 javascript linux firefox firefox-addon mozilla

可能重复。

我想编写可以在 firefox 中执行 linux 命令的 javascript(似乎不可能,但希望问)

通过google,发现IE可以通过“ActiveXObject”。

这里是示例代码:

<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>

那么,在 mozilla 应用程序的 javascript 中是否有任何等效的 ActiveXObject? 我是 javascript 的新手,所以请纠正错误。

谢谢!

最佳答案

在 Firefox 附加组件中,您可以使用 nsIProcess .沿着这些线的东西:

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"]);

当然,此 API 只能由特权代码访问。

关于javascript - 使用javascript在firefox浏览器中评估系统命令或python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7687399/

相关文章:

c - malloc 的内存和 sigsegv

javascript - Dart : capture an image of a Flutter webview

javascript - Angular js : Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader' : parameter 1 is not of type 'Blob'

linux - Jenkins 无法完成执行 "while true"循环的构建脚本

c++ - Linux编程中的多目录 "make"

javascript - 查看页面源代码和在 Firebug 中查看的差异

javascript - document.write() 与插入 DOM 节点 : preserve form information?

javascript - Vue 事件 - 无法监听子组件的 $emit 事件

javascript - 使用超时/间隔的 jQuery 图像幻灯片/旋转横幅问题

html - 带有 ‘stroke-dashoffset’ CSS 动画的 SVG 文本在 Firefox 中不起作用