// Save this as a .js file, e.g. "tee.js"
// Get the command-line arguments
var args = WScript.Arguments;
// Check if a file argument was provided
if (args.length < 1) {
WScript.Echo("Usage: cscript tee.js <output_file>");
WScript.Quit(1);
}
// Get the output file name from the arguments
var outputFile = args(0);
// Create a file object to write to the output file
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(outputFile, 2, true); // 2 = ForWriting, true = Create if not exists
// Read from stdin and write to both stdout and the output file
while (!WScript.StdIn.AtEndOfStream) {
var line = WScript.StdIn.ReadLine();
WScript.Echo(line);
file.WriteLine(line);
}
// Close the output file
file.Close();