javascript - 从 Javascript/XPCOM 调用的批处理文件不显示命令提示符窗口

标签 javascript batch-file xpcom

我以这种方式从 Javascript 调用批处理文件:

function runBatch(){
    var exe = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
    exe.initWithPath("C:\\test.bat");
    var run = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
    run.init(exe);
    var parameters = ["hi"];
    run.run(false, parameters,parameters.length);
}

我的测试批处理文件是:

echo on
echo %1 
pause
exit

但是,每次我调用批处理文件时,都不会显示命令提示符,就像我只是从桌面运行批处理文件一样。我该如何解决这个问题并显示批处理文件的命令提示符?

编辑 明确地说,cmd.exe 进程已启动 - 我可以在任务栏中看到它。但是没有窗口显示。此代码段的行为类似:

function runCmd(){  
var exe = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("C:\\WINDOWS\\system32\\cmd.exe");
var run = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
run.init(exe);
run.run(false, null,0);
}

最佳答案

到目前为止我听到的唯一解决方案(应该有效,虽然我还没有这样做,来自 Mozilla xulrunner IRC channel 中的 Mook:

创建一个临时批处理文件,在批处理文件中写入调用和传递参数。然后执行临时批处理文件。

例如伪代码:

f = fopen("temp.bat"); 
fprintf(f, "other.bat 1 2 3 4 5"); 
fclose(f); 
exec("temp.bat");

不是很优雅,但应该可以。

关于javascript - 从 Javascript/XPCOM 调用的批处理文件不显示命令提示符窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/310996/

相关文章:

javascript - $.cookie 给出错误

javascript - AngularJS 确定 ng-repeat 中的索引

javascript - 使用过滤功能从另一个对象创建对象

url - 在Firefox中加载页面之前修改URL

javascript - Firefox 扩展 : Cancel requests and emit fake responses

javascript - NodeJS 从文件中删除附加数据

windows - 使用 Progress 在 Windows 命令行上复制文件

batch-file - 批处理 : Execute command with quotes in for loop with piping to find

Windows 批量移动到可能不存在的目录

firefox - 如何获取firefox用户代理字符串?