I'm trying to run javascript from a windows command line via script
cscript //NoLogo test.js
However, I can't find any predefined objects which are available. I'm totally at a loss - Can't get hello world to work:
System.print("Hello, World!")
results in "System" is undefined
Is there another way I should be running this - like through .NET runtime?
Thanks
jeff
Try
WScript
:If you really want to run JavaScript in a shell, then you should consider installing Node.js
http://javascript.cs.lmu.edu/notes/commandlinejs/
That is actually JScript and when run with
cscript
orwscript
, it's under the Windows Scripting Host environment, which has no real similarity with web-based javascript.Windows Scripting Host reference
You are using the Windows Scripting Host.
You can say things like:
It's all COM-based, so you instantiate ActiveX controls to do anything useful:
Or:
See Windows Script Host.
This is a very outdated thread, many of the answers are incomplete and/or simply don't work. The way to run JS in shell (regardless if you're using windows or not), is to use Node.js. After you have installed Node, you use it from command line, like this:
or from a file:
Or from node itself: