批处理模式下的 VBScript

VBScript in batch mode

<job>
<script language="VBScript">
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
WshShell.SendKeys "telnet 174.24.2.155 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 5000
WshShell.SendKeys "User + {Enter}"
WScript.Sleep 5000
WshShell.SendKeys "User + {Enter}"
WScript.Sleep 4000
WshShell.SendKeys "Password"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 4000
WshShell.SendKeys "ACCT# + {Enter}"
WScript.Sleep 4000
WshShell.SendKeys "DBSPROCB + {Enter}"
WScript.Sleep 4000
WshShell.SendKeys "SUB + {Enter}"
WScript.Sleep 4000
WshShell.SendKeys "User.RUN.TEST1 + {Enter}"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 4000
WshShell.SendKeys "logoff + {Enter}"
WScript.Sleep 5000
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Quit 
</script>
</job>

从这个 VBscript 提交批处理作业 User.RUN.TEST1 后,我们将收到一条从系统填充的消息。消息是 "Batch has been submitted successfully"。 我想在我的脚本中捕获此消息并想使用 Wscript.echo 显示它,因此有人可以帮助我吗?

您可以使用 stdout.ReadLine:

Dim objShell
Dim objExec
Dim strFromProc
Dim strOutput

Set objShell = WScript.CreateObject("WScript.Shell")
Set objExec = objShell.Exec("cmd.exe /c dir")

' Read output line by line
Do While Not objExec.Stdout.atEndOfStream
    strFromProc = objExec.StdOut.ReadLine()
    strOutput = strOutput & vbCrLf & strFromProc
Loop 

WScript.Echo "Output: " & strOutput