Issues running JScript or VBScript files with UTF-8 encoding thru Windows Script Host
Asked Answered
T

3

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?

Truett answered 20/3, 2014 at 19:10 Comment(0)
S
6

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

Salvidor answered 20/3, 2014 at 19:39 Comment(3)
Yes, that would be my guess too.Truett
Is there any official documentation on this?Fatidic
It would be great to know if this is officially documented anywhere.Primatology
F
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>
Fatidic answered 21/3, 2014 at 6:41 Comment(0)
P
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!

Patras answered 10/2, 2016 at 18:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.