VBScript - 在函数中使用 readline 方法在消息框中显示 shell 命令的结果
VBScript - Displaying results of shell command in message-box using readline method within a function
下面的脚本只显示执行的最后一行cmd
。我不知道如何让它捕获和显示所有 stdout
流。
option explicit
dim wshell, result, box
set wshell = wscript.createobject("wscript.shell")
box = msgbox("Current ARP entries:" &vbcrlf& execstdout("cmd /c arp -a"))
function execstdout(cmd)
set result = wshell.exec(cmd)
do while result.stdout.atendofstream <> true
execstdout = result.stdout.readLine
loop
end function
谁能给我指出正确的方向?
更正代码
option explicit
dim wshell, result, box
set wshell = wscript.createobject("wscript.shell")
box = msgbox("Current ARP entries:" & execstdout("cmd /c arp -a"))
function execstdout(cmd)
set result = wshell.exec(cmd)
do while result.stdout.atendofstream <> true
execstdout = execstdout &vbcrlf& result.stdout.readLine
loop
end function
只需将行 execstdout = result.stdout.readLine
编辑为 execstdout = execstdout & vbcrlf & result.stdout.readLine
。
你总是用下一行替换它。通过此编辑,您可以将所有行连接到一个字符串中,以换行符分隔。
下面的脚本只显示执行的最后一行cmd
。我不知道如何让它捕获和显示所有 stdout
流。
option explicit
dim wshell, result, box
set wshell = wscript.createobject("wscript.shell")
box = msgbox("Current ARP entries:" &vbcrlf& execstdout("cmd /c arp -a"))
function execstdout(cmd)
set result = wshell.exec(cmd)
do while result.stdout.atendofstream <> true
execstdout = result.stdout.readLine
loop
end function
谁能给我指出正确的方向?
更正代码
option explicit
dim wshell, result, box
set wshell = wscript.createobject("wscript.shell")
box = msgbox("Current ARP entries:" & execstdout("cmd /c arp -a"))
function execstdout(cmd)
set result = wshell.exec(cmd)
do while result.stdout.atendofstream <> true
execstdout = execstdout &vbcrlf& result.stdout.readLine
loop
end function
只需将行 execstdout = result.stdout.readLine
编辑为 execstdout = execstdout & vbcrlf & result.stdout.readLine
。
你总是用下一行替换它。通过此编辑,您可以将所有行连接到一个字符串中,以换行符分隔。