Execute
语句的REPL(读取、执行、打印、循环)。If Not LCase( Right( WScript.FullName, 12 ) ) = "\cscript.exe" Then
For Each Arg In WScript.Arguments
If InStr( Arg, " " ) Then Arg = """" & Arg & """"
Str = Str & " " & Arg
Next
WshShell.Run "cscript """ & WScript.ScriptFullName & """" & Str, 1
WScript.Quit
End If
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
@cscript.exe //NoLogo %~dpn0.vbs
If Left(line, 2) = "? " Then line = Replace(line, "? ", "WScript.Echo ", 1, 1)
,以模仿 VBA IDE 的操作。 - Tomalak:
分隔多个语句,例如Sub Test() : Msgbox("Hey") : End Sub
,但当然这很快就会变得笨重。对于更复杂的行为,你需要离开WScript.StdIn.ReadLine()
,例如使用一个循环来读取WScript.StdIn.Read(1)
直到找到特定的“现在运行所有这些”关键字。如果你下定决心,肯定是可行的。 - Tomalak