加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

命令行 – 如何在使用vbscript Exec时显示DOS输出

发布时间:2020-12-14 01:55:02 所属栏目:Windows 来源:网络整理
导读:我有以下VBScript: Set Shell = WScript.CreateObject("WScript.Shell")commandLine = puttyPath "plink.exe -v" " -ssh" [plus additional commands here] Set oExec = Shell.Exec(commandLine) 这会导致出现DOS窗口,但不会显示plink.exe的输出.有没有办
我有以下VBScript:

Set Shell = WScript.CreateObject("WScript.Shell")
commandLine = puttyPath & "plink.exe -v" & " -ssh" [plus additional commands here]    
Set oExec = Shell.Exec(commandLine)

这会导致出现DOS窗口,但不会显示plink.exe的输出.有没有办法让DOS窗口显示此输出?

解决方法

Windows脚本主机缺少一个system()命令所以你必须实现自己的,恕我直言我的助手功能优于stealthyninja的版本,因为它等待进程退出而不只是空stdout,它还处理stderr:

Function ExecuteWithTerminalOutput(cmd)
Set sh = WScript.CreateObject("WScript.Shell")
Set exec =  sh.Exec(cmd)
Do While exec.Status = 0
    WScript.Sleep 100
    WScript.StdOut.Write(exec.StdOut.ReadAll())
    WScript.StdErr.Write(exec.StdErr.ReadAll())
Loop
ExecuteWithTerminalOutput = exec.Status
End Function


call ExecuteWithTerminalOutput("cmd.exe /c dir %windir%*")

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读