6

I'm not sure if I'm doing something wrong, but I can't seem to run the following JScript through the Windows Script Host if I save it in a .js file with the UTF-8 encoding:

var name = "Hello world!";
WScript.echo(name);

When I run it, it gives me this error:

enter image description here

Note that the script runs fine if I save it with ANSI encoding.

Is Windows Script Host engine not compatible with the UTF-8 encoding?

c00000fd
  • 20,994
  • 29
  • 177
  • 400

3 Answers3

5

Possible source file encodings for VBScript and JScript are ANSI or UTF-16 (LE). UTF-8 can't be used.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
5

As an alternative, you can save your file as Windows Script File (.wsf). Apparently, the Windows Script Host does accept XML that is encoded in UTF-8. The script from the question would be written in a WSF as:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<job>
<script language="JScript"><![CDATA[
    var name = "Hello world!";
    WScript.echo(name);
]]></script>
</job>
Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40
0

This works for me:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<job>
<script language="JScript" src="Your-UTF-8-File.js" />
</job>

First problem is that BOM is necessary in js file. Second problem is that I have found no way to enable JScript 5.8 mode from WSF, and Chakra does not work from WSF either. But I use this anyway.

UPD. I have found a better solution: I have a bootloader which conforms to ugly WScript requirements, and inside of it I am reading files with ADODB.Stream in UTF-8 and eval() them, and this way I can run UTF-8 JavaScript without BOM even on Chakra!

OCTAGRAM
  • 618
  • 6
  • 12