也不行,找到一种方法,先对data使用encodeURIComponent编码,
然后在shell.Exec外部用decodeURIComponent对output进行解码,
但是效率就变差了,cscript不能支持JS ES13太遗憾了- @if(0)==(0) echo off
- REM.保存为ANSI编码
- dir /b/a-d/oN "*.txt" | cscript -nologo -e:jscript "%~0"
- pause & goto :EOF
- @end
- fso = new ActiveXObject("Scripting.FileSystemObject");
- var shell = new ActiveXObject("WScript.Shell");
- while (!WSH.StdIn.AtEndOfStream) {
- var file = WSH.StdIn.ReadLine();
- WScript.Echo(file+' 内容:\n');
- //var command = 'cmd /c node -e "console.log(fs.readFileSync(\''+file+'\', \'UTF-8\').toString(\'ascii\'))"';
- var command = '\
- cmd /c node -e "require(\'fs\').readFile(\''+file+'\', \'UTF-8\', function(err, data){\
- console.log(encodeURIComponent(data))\
- })"';
- var execObject = shell.Exec(command);
- var output = execObject.StdOut.ReadAll();
- WScript.Echo(decodeURIComponent(output));
- }
复制代码 |