I have two small programs in VBS and JScript:
VBScript.vbs:
For i=0 To 255
WScript.StdOut.Write Chr(i)
Next
JScript.js:
for ( var i=0; i <= 255; ++i )
WScript.StdOut.Write(String.fromCharCode(i));
When I execute they in the command-prompt, they show different results:
C:>cscript /nologo VBScript.vbs
☺☻♥♦♣
♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]
^_`abcdefghijklmnopqrstuvwxyz{|}~⌂??'ƒ".┼╬^%S<O?Z??''""--~Ts>o?zY ¡¢£¤¥¦§¨©ª«¬®
¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ
ÿ
C:>cscript /nologo JScript.js
☺☻♥♦♣
♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]
^_`abcdefghijklmnopqrstuvwxyz{|}~⌂???????????????????????????????? ¡¢£¤¥¦§¨©ª«¬
®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüý
þÿ
Previous output may be explained because some operative difference in JScript's fromCharCode method vs. VBScript's Chr function. However, if a try to redirect the output to a disk file, the result is very different:
C:>cscript /nologo VBScript.vbs > VBScript.txt
C:>cscript /nologo JScript.js > JScript.txt
C:\JScript.js(2, 4) Microsoft JScript runtime error: Invalid procedure call or argument
C:>dir *.txt
15/01/2013 05:48 p.m. 128 JScript.txt
15/01/2013 05:48 p.m. 256 VBScript.txt
In this case, both programs use the same WSH method under the same conditions, so I don't understand why VBS correctly generate the file with 256 characters, but JScript issue an error and just generate the first 128 characters.
What happens here? Is there a way to correctly generate the same file with 256 different characters in JScript? TIA
Antonio