Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 277
c00000fd Avatar asked Mar 20 '14 19:03

c00000fd


2 Answers

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

like image 145
Ekkehard.Horner Avatar answered Nov 09 '22 22:11

Ekkehard.Horner


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>
like image 4
Cheran Shunmugavel Avatar answered Nov 09 '22 21:11

Cheran Shunmugavel