vbscript output to console
You mean:
Wscript.Echo "Like this?"
If you run that under wscript.exe
(the default handler for the .vbs extension, so what you'll get if you double-click the script) you'll get a "MessageBox" dialog with your text in it. If you run that under cscript.exe
you'll get output in your console window.
This was found on Dragon-IT Scripts and Code Repository.
You can do this with the following and stay away from the cscript/wscript differences and allows you to get the same console output that a batch file would have. This can help if your calling VBS from a batch file and need to make it look seamless.
Set fso = CreateObject ("Scripting.FileSystemObject")Set stdout = fso.GetStandardStream (1)Set stderr = fso.GetStandardStream (2)stdout.WriteLine "This will go to standard output."stderr.WriteLine "This will go to error output."
You only need to force cscript instead wscript. I always use this template. The function ForceConsole() will execute your vbs into cscript, also you have nice alias to print and scan text.
Set oWSH = CreateObject("WScript.Shell") vbsInterpreter = "cscript.exe" Call ForceConsole() Function printf(txt) WScript.StdOut.WriteLine txt End Function Function printl(txt) WScript.StdOut.Write txt End Function Function scanf() scanf = LCase(WScript.StdIn.ReadLine) 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 "| | | '_| . | | --| | | | . | |__ | _| _| | . | _|" printf "|__|__|_|_,_|___|_|_|_____|_____|___| |_____|___|_| |_| _|_| " printf " |_| v1.0" printl " Enter your name:" MyVar = scanf cls printf "Your name is: " & MyVar wait(5)