Himanshu
Himanshu

Reputation: 825

How to hide command prompt window while running .bat file using nsIProcess?

My code:

var fpath="C:\\TVT_"+cur_date+"_"+cur_time+".avi";

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.. & cd.. & C: & cd C:/ffmpeg/bin & record.bat "+fpath];

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

When I execute the batch file through this code then always a command prompt window prompt displays.

Is there any way to hide that window and run batch process silently ?

Using Windows XP and Firefox 12.0

Thanks..

Upvotes: 0

Views: 2897

Answers (2)

Wladimir Palant
Wladimir Palant

Reputation: 57651

I don't think that Firefox can run a batch file without a console window. However, this is possible using Windows Scripting Host via WshShell.Run() (intWindowStyle parameter must be 0). You would need a JScript file, e.g. record.js with the contents:

var dir = WScript.ScriptFullName.replace(/[\/\\]+[^\/\\]*$/, "");
var Shell = WScript.CreateObject("Wscript.Shell");
Shell.CurrentDirectory = dir;
Shell.Run("record.bat", 0, true);

This script deduces the directory from its own path and runs record.bat in the same directory. You could then run this script like this:

var script = new FileUtils.File("c:\\ffmpeg\\bin\\record.js");

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

Upvotes: 1

s.webbandit
s.webbandit

Reputation: 17000

To run batch process silently add @echo off at the first line of it.

Upvotes: 0

Related Questions