vbscript .run 显示输出 [英] vbscript .run show output
问题描述
我可以使用语法成功运行 test.vbs:
Dim WshShellSet WshShell = CreateObject("WScript.Shell")sEXE = """\\uncpath\file.exe"""与 CreateObject("WScript.Shell").Run sEXE &" ", 1, true ' 等待完成或 False 不等待以
但是我想将输出存储到 \\\uncpath\%computername%.txt
这不起作用:
sEXE = """\\uncpath\file.exe>>\\uncpath\%computername%.txt"""与 CreateObject("WScript.Shell").Run sEXE &" ", 1, true ' 等待完成或 False 不等待以
<块引用>
错误行:使用 CreateObject("WScript.Shell")
这也行不通.
sEXE = """\\uncpath\file.exe"""与 CreateObject("WScript.Shell").Run sEXE &" >>\\uncpath\%computername%.txt", 1, true ' 等待完成或 False 不等待以
有什么帮助吗?
.Run()
方法无法读取您使用 的任务的标准输出.Exec()
为此,但您需要进行一些更改来模拟 .Run()
自动为您执行的阻塞.
Dim WshShell、sEXE、cmd、结果Set WshShell = CreateObject("WScript.Shell")sEXE = """\\uncpath\file.exe"""使用 CreateObject("WScript.Shell")设置 cmd = .Exec(sEXE)'阻塞直到完成.Do While cmd.Status <>1WScript.Sleep 100环形'获取输出结果 = cmd.StdOut.Readall()'检查输出WScript.Echo 结果设置 cmd = 无结束于
<小时>
另一种方法是在 sEXE
变量前加上前缀,这样您就可以使用 cmd/c
(作为 >>>
命令是其中的一部分).
这应该有效
sEXE = "cmd/c ""\\uncpath\file.exe >> \\uncpath\%computername%.txt"""使用 CreateObject("WScript.Shell").Run sEXE &" ", 1, true ' 等待完成或 False 不等待结束于
<小时>
有用的链接
- WshScriptExec 对象 (由
.Exec()
返回) - TextStream 对象 (由
.StdIn
、StdOut
和StdErr
返回)
I can run successfully test.vbs with syntax:
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
sEXE = """\\uncpath\file.exe"""
with CreateObject("WScript.Shell")
.Run sEXE & " ", 1, true ' Wait for finish or False to not wait
end with
however I want to store the output to \\\uncpath\%computername%.txt
This doesn't work:
sEXE = """\\uncpath\file.exe>>\\uncpath\%computername%.txt"""
with CreateObject("WScript.Shell")
.Run sEXE & " ", 1, true ' Wait for finish or False to not wait
end with
error with line: with CreateObject("WScript.Shell")
This doesn't work either.
sEXE = """\\uncpath\file.exe"""
with CreateObject("WScript.Shell")
.Run sEXE & " >>\\uncpath\%computername%.txt", 1, true ' Wait for finish or False to not wait
end with
any help?
The .Run()
method doesn't have the ability to read the standard output from a task you use .Exec()
for that, but you need a few changes to simulate the blocking that .Run()
does for you automatically.
Dim WshShell, sEXE, cmd, result
Set WshShell = CreateObject("WScript.Shell")
sEXE = """\\uncpath\file.exe"""
With CreateObject("WScript.Shell")
Set cmd = .Exec(sEXE)
'Block until complete.
Do While cmd.Status <> 1
WScript.Sleep 100
Loop
'Get output
result = cmd.StdOut.Readall()
'Check the output
WScript.Echo result
Set cmd = Nothing
End With
The other approach is to prefix the sEXE
variable so you are using cmd /c
(as the >>
command is part of that).
This should work
sEXE = "cmd /c ""\\uncpath\file.exe >> \\uncpath\%computername%.txt"""
With CreateObject("WScript.Shell")
.Run sEXE & " ", 1, true ' Wait for finish or False to not wait
End With
Useful Links
- WshScriptExec Object (Returned by
.Exec()
) - TextStream Object (Returned by
.StdIn
,StdOut
andStdErr
)
这篇关于vbscript .run 显示输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!