

It transparently '= switches to CScript if the script has been started in WScript.
#Vbscript print to stdout code#
Here is the code for the cCONSOLE class CLASS cCONSOLE '= '= '= This class provides automatic switch to CScript and has methods '= to write to and read from the CSCript console. Pause End With '= End of script - the cCONSOLE class code follows here Box sMsg '// Pause with the message "Hit enter to continue". prompt( "Enter any text:" ) '// Write out the text in a box. print "Arg(" & ix & ")=" & wscript.arguments(ix) next '// Prompt for some text from the user dim sMsg : sMsg =.

Print "Arg count=" & '// List all the arguments on the console log dim ix for ix = 0 to -1. print "CSCRIPT Console demo script" '// Arguments are passed through correctly, if present. Here is an example: Option Explicit '// Instantiate the console object, this automatically switches to CSCript if required Dim CONS: Set CONS = New cCONSOLE '// Now we can use the Consol object to write to and read from the console With CONS '// Simply write a line. To use it, include the complete class at the end of your script, and then instantiate it right at the beginning of the script. This assumes that your objective is to stream output to the console, rather than having output go to message boxes.

I came across this post and went back to an approach that I used some time ago which is similar to main difference is that it uses a VBScript user-defined class to wrap all the logic for switching to CScript and outputting text to the console, so it makes the main script a bit cleaner. Set oWSH = CreateObject("WScript.Shell") vbsInterpreter = "cscript.exe" Call ForceConsole() Function printf(txt) txt End Function Function printl(txt) txt End Function Function scanf() scanf = LCase() End Function Function wait(n) WScript.Sleep Int(n * 1000) End Function Function ForceConsole() If InStr(LCase(WScript.FullName), vbsInterpreter) = 0 Then oWSH.Run vbsInterpreter & " //NoLogo " & Chr(34) & WScript.ScriptFullName & Chr(34) WScript.Quit End If End Function Function cls() For i = 1 To 50 printf "" Next End Function printf " _ _ _ _ _ _ _ _ " printf "| _ |_| |_ _ _| |_ _ _ _| | | _|_ _|_|_| |_ " printf "| | | '_|. The function ForceConsole() will execute your vbs into cscript, also you have nice alias to print and scan text. You only need to force cscript instead wscript.
