如何将变量从批处理传递到 Javascript
How to pass variable from batch to Javascript
我有一个批处理文件可以检查一个文件夹中有多少张图片。
我怎样才能return这个值回到调用批处理文件的JavaScript?
dir /B /A-D /S "C:\Users\Viktor\Desktop\Images\*.jpg" | find /N /C /V ""
pause
这是从 JavaScript:
运行批处理文件的代码
var file = null;
var process = null;
var args = [""];
// create an nsIFile for the executable
file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
file.initWithPath("C:\Users\Viktor\Desktop\file.bat");
// create an nsIProcess
process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(file);
// Launch the process
process.run(false , args, args.length);
要 return 将变量值恢复为 JavaScript,请尝试从该批处理中使用找到的变量值作为参数重新启动 JavaScript 文件。在 JavaScript 文件中添加一个开关,以在定义该参数时绕过再次调用批处理。
当你只能使用你的浏览器和 imacros .js 时,我不知道你为什么需要这个批处理文件
在浏览器中打开文件夹:file:///C:/Users/Viktor/Desktop/Images/
然后 运行 iMacros 中的这个 .js:
var img = new Array();
iimPlayCode("TAG POS=1 TYPE=BODY ATTR=* EXTRACT=TXT");
img = iimGetExtract().split(".jpg");
alert(img.length-1);
您可以使用以下语法将 dir 命令的结果重定向到新的 HTML 文件中:
dir /B /A-D /S "C:\Users\Viktor\Desktop\Images\*.jpg" | find /N /C /V "">>yourFile.html
这会将 .bat 结果写入您的 html。
我有一个批处理文件可以检查一个文件夹中有多少张图片。 我怎样才能return这个值回到调用批处理文件的JavaScript?
dir /B /A-D /S "C:\Users\Viktor\Desktop\Images\*.jpg" | find /N /C /V ""
pause
这是从 JavaScript:
运行批处理文件的代码var file = null;
var process = null;
var args = [""];
// create an nsIFile for the executable
file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsIFile);
file.initWithPath("C:\Users\Viktor\Desktop\file.bat");
// create an nsIProcess
process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
process.init(file);
// Launch the process
process.run(false , args, args.length);
要 return 将变量值恢复为 JavaScript,请尝试从该批处理中使用找到的变量值作为参数重新启动 JavaScript 文件。在 JavaScript 文件中添加一个开关,以在定义该参数时绕过再次调用批处理。
当你只能使用你的浏览器和 imacros .js 时,我不知道你为什么需要这个批处理文件
在浏览器中打开文件夹:file:///C:/Users/Viktor/Desktop/Images/
然后 运行 iMacros 中的这个 .js:
var img = new Array();
iimPlayCode("TAG POS=1 TYPE=BODY ATTR=* EXTRACT=TXT");
img = iimGetExtract().split(".jpg");
alert(img.length-1);
您可以使用以下语法将 dir 命令的结果重定向到新的 HTML 文件中:
dir /B /A-D /S "C:\Users\Viktor\Desktop\Images\*.jpg" | find /N /C /V "">>yourFile.html
这会将 .bat 结果写入您的 html。