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:
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?
Possible source file encodings for VBScript and JScript are ANSI or UTF-16 (LE). UTF-8 can't be used.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With