Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows command line javascript

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

like image 400
theschmitzer Avatar asked Mar 26 '09 15:03

theschmitzer


2 Answers

That is actually JScript and when run with cscript or wscript, it's under the Windows Scripting Host environment, which has no real similarity with web-based javascript.

Windows Scripting Host reference

like image 95
spoulson Avatar answered Sep 29 '22 00:09

spoulson


You are using the Windows Scripting Host.

You can say things like:

WScript.Echo("Hello, World.");

It's all COM-based, so you instantiate ActiveX controls to do anything useful:

var y = new ActiveXObject("Scripting.Dictionary");
y.add ("a", "test");
if (y.Exists("a"))
   WScript.Echo("true");

Or:

var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
// Get a File object to query.
f1 = fso.GetFile("c:\\detlog.txt");   
// Print information.
Response.Write("File last modified: " + f1.DateLastModified);

See Windows Script Host.

like image 25
2 revs Avatar answered Sep 28 '22 23:09

2 revs