以下是我当前小项目的当前脚本。
<job>
<script language="VBScript">
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe", 2
WScript.Sleep 50
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet 192.168.0.1 23"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 50
WshShell.SendKeys ("root{Enter}")
WScript.Sleep 50
WshShell.SendKeys ("foo{Enter}")
WScript.Sleep 50
WshShell.SendKeys ("cd /work/Tools{Enter}")
WScript.Sleep 50
WshShell.SendKeys ("control_videosignal.sh -fbas 1{Enter}")
WScript.Sleep 50
WshShell.SendKeys "exit{ENTER}" 'close telnet session'
WshShell.SendKeys "{ENTER}" 'get command prompt back
WScript.Sleep 50
WshShell.SendKeys "exit{ENTER}" 'close cmd.exe
WshShell.SendKeys "{ENTER}" 'get command prompt back
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}" 'get command prompt back
WScript.Sleep 200
WshShell.SendKeys "exit{ENTER}" 'close cmd.exe
</script>
</job
结果就是它停在了这一点。
我只是希望当脚本退出时关闭当前 cmd.exe 窗口。
任何帮助都将受到赞赏。
WshShell.SendKeys ("control_videosignal.sh -fbas 1{Enter}")
WScript.Sleep 50
WshShell.SendKeys ("{Enter}")
WScript.Sleep 200
WshShell.SendKeys "^{C}"
WScript.Sleep 200
WshShell.SendKeys ("exit{Enter}")
WScript.Sleep 3000
WScript.Quit
</script>
</job>
连接未执行就关闭。
答案1
看起来您被困在 Telnet 中,它使用命令quit
而不是exit
我相信的。
尝试使用:
WshShell.SendKeys "quit{ENTER}"
或者
WshShell.SendKeys "^{C}"
为了确保您已正确退出 Telnet,在发出exit
之前cmd
。