cscript - print output on same line on console? cscript - print output on same line on console? windows windows

cscript - print output on same line on console?


Use WScript.StdOut.Write() instead of WScript.Print().


WScript.Print() prints a line, and you cannot change that. If you want to have more than one thing on that line, build a string and print that.

Dim s: s = ""for a = 1 to 10  s = s & "."  REM (do something)nextprint s

Just to put that straight, cscript.exe is just the command line interface for the Windows Script Host, and VBScript is the language.


I use the following "log" function in my JavaScript to support either wscript or cscript environment. As you can see this function will write to standard output only if it can.

var ExampleApp = {    // Log output to console if available.    //      NOTE: Script file has to be executed using "cscript.exe" for this to work.    log: function (text) {        try {            // Test if stdout is working.            WScript.stdout.WriteLine(text);            // stdout is working, reset this function to always output to stdout.            this.log = function (text) { WScript.stdout.WriteLine(text); };        } catch (er) {            // stdout is not working, reset this function to do nothing.            this.log = function () { };        }    },    Main: function () {        this.log("Hello world.");        this.log("Life is good.");    }};ExampleApp.Main();