Show me the code! – By Davanum Srinivas

September 10, 2008

[Ubiquity] Shell – Launch an external process

Filed under: Uncategorized — Davanum Srinivas @ 11:51 am

Thanks to the greasemonkey folks. Pretty easy to launch an external process. One caveat, you need the full path of the executable.

CmdUtils.CreateCommand({
    name: "shell",
    takes: {"commandLine": noun_arb_text},  
    execute: function(commandLine) {
      var process = Components.classes["@mozilla.org/process/util;1"]
                            .createInstance(Components.interfaces.nsIProcess);
      var args = commandLine.text.split(" ");
      var executable = Components.classes["@mozilla.org/file/local;1"]
                  .createInstance(Components.interfaces.nsILocalFile);
      executable.followLinks = true;
      executable.initWithPath(args[0]);
 
      if (executable.exists() && executable.isExecutable()) {
        process.init(executable);
        args.splice(0,1);
        process.run(false, args, args.length);
      } else {
        displayMessage(args[0] + ' is not an executable');
      }
    },

    preview: function(pblock, commandLine) {
      var args = commandLine.text.split(" ");
      s = " Runs the following command: " + args[0] + "<br>";
      args.splice(0,1);
      s += "                   arguments: " + args;
      pblock.innerHTML = s; 
    }
})

2 Comments »

  1. This does not work. I try to run cmd (C:\Windows\System32\cmd.exe) with the command
    shell C:\Windows\System32\cmd.exe

    but nothing happens.

    Comment by Niklas — February 3, 2009 @ 1:40 pm

    • Thanks for “shell”

      I run Windows console applications from Mozilla addons via such .vbs script:

      Dim command
      command = “”
      For Each arg in WScript.Arguments
      command = command & arg & ” ”
      Next

      Set WshShell = WScript.CreateObject(“WScript.Shell”)
      WshShell.Run command

      Comment by bntr — May 7, 2009 @ 11:06 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: