English 中文(简体)
使用 nsIProcess 运行.bat 文件时如何隐藏命令提示窗口?
原标题:How to hide command prompt window while running .bat file using nsIProcess?

<强> 我的代码:

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

当我通过此代码执行批量文件时, 总是有一个命令提示窗口提示显示 。

是否有办法隐藏那个窗口 并秘密地运行批量过程?

启用 Windows XP 和 Firefox 12. 0

谢谢

最佳回答

我不认为 Firefox 可以在没有控制台窗口的情况下运行批次文件 。 但是, 这可以使用 Window 脚本主机 < a href=> http://msdn.microsoft.com/ en- us/library/d5fk67ky% 28v=vs. 84%29. aspx" rel="nofollow"\\code>Wshshshell.Run () ( intWindowStyle 参数必须为 0 ) 。 您需要包含内容的 JScript 文件, 例如 record.js :

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

此脚本从自己的路径中导出目录, 并在同一目录中运行 < code> record.bat 。 您可以这样运行此脚本 :

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);
问题回答

要运行批量处理,请在第一行中静悄悄地添加





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签