isync
isync

Reputation: 537

How to execute a command in a Firefox Add-On?

I am quite new to writing Firefox Add-Ons, still, I got to a point where I patched together a working extension, except the very core of it.

At some point in the code, I need to execute a system-command on a file. I've found a snipped on the web and tried to adapt it, but without luck. From my xpi/components/script.js:

var cmd = '/usr/bin/somecommand'

var args = ['-option', 'value', f.path ];

var execFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);

execFile.initWithPath(cmd);

if (execFile.exists()) {
    process.init(execFile);
    process.run(false, args, args.length);
}

Can someone tell me what's wrong here? I've assembled the command and I've got the filename but I can't get Firefox to execute this code snippet.

Is this execFile, initWithPath, createInstance, etc. stuff really needed?? I just want to execute the command just like in the CLI:

$ somecommand -option value filename

Upvotes: 3

Views: 1835

Answers (1)

Nickolay
Nickolay

Reputation: 32071

Works fine for me with cmd and args changed to:

var cmd = '/usr/bin/say';
var args = ['hello', 'world' ];

As Neil says, we need more info for troubleshooting. Enable the Error Console and check if there are any messages there.

Upvotes: 1

Related Questions