do while true
wscript.stdout.write(">>> ")
ln = wscript.stdin.readline
if lcase(trim(ln)) = "exit" then exit do
on error resume next
err.clear
execute ln
if err.number <> 0 then wscript.echo(err.description)
on error goto 0
loop
Note that this is totally daft and it doesn’t do anythng complex at all. No line continuations. No cleverness. But it helps me to answer the sorts of questions I come up with a lot, like “does a string with length > 0 evaluate to True?” without having to create a .vbs file and run it. You need to run this from the command line with cscript.
And this is VBScript interactive shell, written , and concerning Uncategorized
Comments
Ha, great minds think alike!
I wrote a GUI (WScript) version of this a while back. Here's the whole thing (hope it displays right):
<pre><code>
OPTION EXPLICIT
DIM strCodeToExec
strCodeToExec = "msgbox Now()"
DO WHILE strCodeToExec<>""
strCodeToExec = InputBox("Enter VBS code to execute", "WSH Prompt", strCodeToExec)
IF strCodeToExec<>"" THEN
on error resume next
execute(strCodeToExec)
IF err.Number<>0 THEN
call msgbox("Error #" & err.number & vbCRLF & err.description, vbExclamation, "Run Error")
END IF
on error goto 0
END IF
LOOP
</code></pre>
It just prompts for code (with an inputbox), execs that code & then asks for more. Quite handy.
Btw, it's downloadable as "WSHPrompt" at http://slingfive.com/pages/tools/.
How does the original script work?
There’s no such object as “wscript“. How do you create such an object?
I’d really love to see a working version of this.
Thanks,
Martin
Martin: put the code in a file called “vbs.vbs“, and then run it with “cscript //nologo vbs.vbs“.
Martin, this is an *incredibly* useful script. I find being able to prototype my code interactively to be such a huge productivity win - I think *every* interpreted language should provide such a thing.
Thanks so much!
-Chris
Do you have a Fortran version? :)
I agree with you, the interactive shell is one of the best things about Python. Everytime I'm coding in Fortran (really, I do that) I almost get crazy.