Windows Script Host
Revision as of 14:31, 14 April 2005 by 161.253.9.181 (talk)
Launching
At the console, type
cscript //nologo scriptname.js
The //nologo is optional; it suppresses the version output (which, for reasons unknown, is output on default!).
Console I/O
To write to stdout, use the WScript.StdOut object. For stderr, WScript.StdErr.
WScript.StdOut.Write("something");
WScript.StdErr.WriteLine("something that's a line");
WScript.StdIn, of course, corresponds to stdin.
var input = ""; while(!WScript.StdIn.AtEndOfLine) input += WScript.StdIn.Read(1); // read 1 character
var stdin = WScript.StdIn;
var stdout = WScript.StdOut;
while(!stdin.AtEndOfStream)
{
var str = stdin.ReadLine();
stdout.WriteLine("Line " + (stdin.Line - 1) + ": " + str);
}