在chrome / firefox上从javascript执行bat文件

时间:2015-06-29 09:49:07

标签: google-chrome batch-file firefox

我尝试使用ActiveXobject运行此批处理文件,但这仅适用于IE。我可以获得在Chrome / Firefox上运行它的解决方案吗?

1 个答案:

答案 0 :(得分:0)

如果您正在开发Firefox扩展,则以下代码有效。它启动D:\ test.bat文件。

var file        = null;
var process     = null;
var args        = [""];

// create an nsIFile for the executable
file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
file.initWithPath("D:\\test.bat");

// create an nsIProcess
process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(file);

// Launch the process
process.run(false , args, args.length);
相关问题