1

私はプログラマーではないので、このフォーラムの素晴らしい人々を過度に苛立たせたくありません。私の問題は、VBScript を使用して Linux デバイスに Telnet で接続し、DFコマンドを発行して、後で解析できるログ ファイルにすべての応答を出力したいということです。私は当初、Telnet を正常に実行する方法を見つけましたが、テキスト ファイルの出力要件に関しては成功しませんでした。次のコードは確かに機能しませんが、正しい方法に近いかどうか疑問に思っていますか?

Dim WshShell, oExec  
Set WshShell = CreateObject("WScript.Shell")  
Set oExec = WshShell.Exec("cmd /c dir")

WshShell.run"cmd" '*** open command window ***  
WScript.Sleep 250  

WshShell.SendKeys("{Enter}")  
WshShell.SendKeys"telnet 10.13.2.2"  
WshShell.SendKeys("{Enter}")  
WScript.Sleep 2000  

WshShell.SendKeys"root"  
WshShell.SendKeys("{Enter}")  
WScript.Sleep 1500  

WshShell.SendKeys"password"  
WshShell.SendKeys("{Enter}")  
WScript.Sleep 1500  

Set objFSO  = CreateObject("Scripting.FileSystemObject")  
Set objLogFile = objFSO.OpenTextFile("C:\VBSmemSize.txt", 2, True)  

WshShell.SendKeys"df /mnt/cf"  
WshShell.SendKeys("{Enter}")  
Do  
  strFromProc = oExec.Stdout.Readline()  
  WScript.Echo strFromProc  
Loop While Not objLogFile.StdOut.atEndOfStream  
4

1 に答える 1

0

外部コマンドからの出力をキャプチャすることはできますが、sendkeysのように同時にそれらと対話することはできません。これが機能する例です

Function ExecPing(strTarget)
  Set objShell = CreateObject("WScript.Shell")
  Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
  strPingResults = LCase(objExec.StdOut.ReadAll)
  If InStr(strPingResults, "antwoord van") Then '"reply from" in E
    WScript.Echo VbCrLf & strTarget & " responded to ping."
    ExecPing = True
  Else
    WScript.Echo VbCrLf & strTarget & " did not respond to ping."
    ExecPing = False
  End If
End Function

ExecPing pcname
于 2012-06-01T08:08:50.637 に答える