Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I start an interactive console for VBS?

Very similar to this question:

How can I start an interactive console for Perl?

I just want to be able to start entering VBS statements, one at a time, and have them evaluated straight away, like Python's IDLE.

like image 665
user814116 Avatar asked Feb 26 '13 10:02

user814116


1 Answers

I wrote this a couple years ago. It's based on this blog post (archived here), but with a couple enhancements. Essentially it's a REPL (Read, Execute, Print, Loop) using the Execute statement:

Do While True
    WScript.StdOut.Write(">>> ")

    line = Trim(WScript.StdIn.ReadLine)

    If LCase(line) = "exit" Then Exit Do

    On Error Resume Next
    Execute line
    If Err.Number <> 0 Then
        WScript.StdErr.WriteLine Err.Description
    End If
    On Error Goto 0
Loop

I usually start it with a batch file of the same name (i.e. "vbs.vbs" and "vbs.bat"), like this:

@cscript.exe //NoLogo %~dpn0.vbs
like image 122
Ansgar Wiechers Avatar answered Oct 12 '22 02:10

Ansgar Wiechers