JScript is crashing with a very poor reason given

108 views Asked by At

I have the following code which works should theoretically work well:

var arg = WScript.arguments(0);
alert(arg.toString);

So when I run it in CMD, like this: hello_world.js "Sup"

It'll get a runtime error immediately at line 2 with the reason being: Object expected

But these docs say the alert function expects a string argument: http://www.w3schools.com/jsref/met_win_alert.asp

And actually.... it gets worse.

This will result in the same crash with the same runtime:

alert("ummm wtf...");

Is Microsoft JScript just useless or am I doing something wrong?

1

There are 1 answers

0
npocmaka On

Jscript is case sensitive . Try with:

   WScript.Echo(WScript.Arguments.Item(0));

In WSH there's no alert , and you need to use WScript.Echo

you can call the script like this cscript /e:jscript /nologo script.js or wscript /e:jscript /nologo script.js .The first will output the messages in the console the second with pop-ups.

If you need to use alert you'll need MSHTA - http://www.brivers.com/resume/scripts/tutorial-hta.php