5

我尝试使用 nsIProcess 执行 .exe 文件。但它不起作用,也没有给出任何错误消息。我正在使用 Firefox 10 和 Windows 7。有人可以建议我任何解决方案吗?谢谢

var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIProcess);
file.initWithPath("C:\\Users\MJ\\Desktop\\Example.FaceDetection.exe");  
file.launch(); 
4

1 回答 1

10

您之前忘记了一个反斜杠MJ

file.initWithPath("C:\\Users\\MJ\\Desktop\\Example.FaceDetection.exe");

因此,您的应用程序不会执行,因为它没有被发现。也就是说,运行应用程序的更好方法通常是nsIProcess - 它允许您指定命令行参数,它还将提供有用的反馈:

var params = ["foo", "bar"];
var process = Components.classes["@mozilla.org/process/util;1"]
                        .createInstance(Components.interfaces.nsIProcess);
process.init(file);
process.run(false, params, params.length);
于 2012-07-18T06:10:13.380 回答