0

I successfully executed commands and .bat files in command prompt using XUL by this code:

Components.utils.import("resource://gre/modules/FileUtils.jsm");

var env = Components.classes["@mozilla.org/process/environment;1"]
                    .getService(Components.interfaces.nsIEnvironment);
var shell = new FileUtils.File(env.get("COMSPEC"));

var args = ["/c", "cd C:/ffmpeg/bin & record.bat"];

var process = Components.classes["@mozilla.org/process/util;1"]
                        .createInstance(Components.interfaces.nsIProcess);
process.init(shell);
process.runAsync(args, args.length);

But now I changed .bat files to .sh files to run for Ubuntu and need to run commands in terminal by using same code, so I need to change environment variable "COMSPEC" to something which works for terminal, I found that it is "TERM" but didn't work.

Is there any other environment variable or way to do this task?

Makyen
  • 31,849
  • 12
  • 86
  • 121
Himanshu
  • 825
  • 2
  • 10
  • 24

1 Answers1

0

The command to run shell files on Linux is fixed - it is always /bin/sh. So you would do:

var shell = new FileUtils.File("/bin/sh");
var args = ["-c", "record.sh"];

This isn't quite the correct approach - if you wanted to do it absolutely correctly you would look inside the script file and parse the first line (which is usually something like #!/bin/sh). And in the general case you wouldn't check the file extension but rather whether the file is executable (on Unix-like systems this is completely independent of the file extension). But I guess that you aren't very interested in the general case.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • 1
    You are right Wladimir..but if I run "cd /home/himanshu/ffmpeg && chmod +x record.sh && sudo ./record.sh" command directly in terminal then it runs good, I need something like "COMSPEC" which can take place inside "env.get('----')" ? – Himanshu May 28 '12 at 12:26