簡體   English   中英

vbscript.run show output

[英]vbscript .run show output

我可以使用以下語法成功運行 test.vbs:

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

但是我想將 output 存儲到\\\uncpath\%computername%.txt

這不起作用:

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

行錯誤:使用 CreateObject("WScript.Shell")

這也不起作用。

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

有什么幫助嗎?

.Run()方法無法從使用.Exec()的任務中讀取標准輸出,但是您需要進行一些更改以模擬.Run()為您自動執行的阻止。

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

另一種方法是給sEXE變量sEXE前綴,以便您使用cmd /c (因為>>命令是該命令的一部分)

這應該工作

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

有用的鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM