2011-02-03 2 views
4

を使用するときにDOSの出力を表示するために、私は次のVBScriptを持っている:どのようにVBScriptのExecの

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ウィンドウにこの出力を表示する方法はありますか?

答えて

3

のWindowsスクリプティングホストは、システム()コマンドを欠いており、空のstdoutと、それだけではなく、また、標準エラー出力を処理します。

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%\*") 
+0

READALLは、ブロックしている私は –

+0

@JS考えるReadLineメソッドでなければなりません除いて良いルックス:はい、それがブロックしているが、あなたはおそらく限り、WriteLineメソッド+ ReadLineメソッドにそれを変更することができます出力はテキストベースであり、何らかのバイナリpの一部ではないipeの操作。 – Anders

+0

このコードは機能しません。私はそれがなぜ受け入れられる答えなのだろうと思う。 – Ghigo

4

@JC:試してみてください - あなたがあなた自身を実装する必要がありますので、それはプロセスの終了を待っているので、私のヘルパー関数がstealthyninjaのバージョンに比べて優れているIMHO

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

Set oStdOut = Shell.StdOut 

While Not oStdOut.AtEndOfStream 
    sLine = oStdOut.ReadLine 
    WScript.Echo sLine 
Wend 
関連する問題