VBscript write to command console

Filip 831 Reputation points
2021-04-14T09:21:06.297+00:00

Hello everybody.
Can i run .vbs file in the command line and get there printed output?
I tried :

Dim StdOut : Set StdOut = CreateObject("Scripting.FileSystemObject").GetStandardStream(1)  
  
WScript.Echo "Hello"  
WScript.StdOut.Write "Hello"  
WScript.StdOut.WriteLine "Hello"  
Stdout.WriteLine "Hello"  
Stdout.Write "Hello"  

87672-a.png

Thanks for help.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
23,931 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 82,911 Reputation points
    2021-04-14T11:12:50.243+00:00

    Use WScript.Echo "Hello" line only (remove other lines) and start the script in console using this command: cscript test.vbs.


  2. MotoX80 23,651 Reputation points
    2021-04-20T13:44:59.073+00:00

    Windows has 2 VB script processors, WScript.exe (GUI) and CScript.exe (console). To get the output to display in a command prompt you have to use cscript.exe.

    cscript.exe C:\MyScriptsFolder\MyScript.vbs  
    

    If you just type in the script name Windows will use the default which is wscript.exe. You can change that from an admin command prompt.

    cscript.exe //H:CScript  
    

    89582-capture.jpg

    No comments