看板 Visual_Basic 關於我們 聯絡資訊
推 noar:是在2005嗎??我2003沒有看到咧 沒錯, 是.NET2.0後才加入的東西~ 那回到你最原先要的取代執行結果的做法是.. Imports System.IO ' for StreamReader, 讀取console的output Imports System.Diagnostics ' for Process 執行 ping(或.bat)執行 ' 你應該也是用 Process來執行 bat檔吧? Dim p As Process = New Process() ' 這兩行是關鍵, 一定要這樣設~ p.StartInfo.RedirectStandardOutput = True p.StartInfo.UseShellExecute = False ' 執行程式與參數. 然後要記得 Start() p.StartInfo.FileName = "ping" p.StartInfo.Arguments = "192.168.1.30" p.Start() ' 把 Output重新導到 StreamReader, 然後一次全部讀下來.. Dim reader As StreamReader = p.StandardOutput Dim result As String = reader.ReadToEnd() 像這樣的話, 就是 ping 程式結束後一次 Return所有的內容.. 如果你的 bat程式不會終止, 或執行時間比較久, 若你想更即時一點看到內容, 就要用 ReadLine()或Read()來讀 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.139.141.64 ※ 編輯: cole945 來自: 220.139.141.64 (06/13 16:13)
noar:感謝囉..不過我應該會灌2005用地一個方法吧 感恩 06/13 16:34
noar:第一個方法很優喔!!再次感謝 06/13 16:45