Mangala Edirisinghe
Mangala Edirisinghe

Reputation: 1111

how to execute an external application using firefox addon?

I try to execute .exe file using nsIProcess. But it is not working and not giving any error message. I am working on firefox 10 and windows 7. Can anybody suggest me any solution? Thanks

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

Upvotes: 5

Views: 6476

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57691

You forgot one backslash before MJ:

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

So your application doesn't execute because it isn't being found. That said, the better way to run applications is usually nsIProcess - it allows you to specify command line parameters and it will also provide useful feedback:

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

Upvotes: 10

Related Questions