2011-06-16 45 views
0

我正在使用VB.net在命令行程序的頂部有一個GUI。在VB.net中響應命令行程序問題

Dim sqliProcess As New Process() 
sqliProcess.StartInfo.UseShellExecute = False 
sqliProcess.StartInfo.RedirectStandardOutput = True 
sqliProcess.StartInfo.RedirectStandardError = True 
sqliProcess.StartInfo.FileName = "C:\shell_program.exe" 
sqliProcess.StartInfo.CreateNoWindow = True 
sqliProcess.Start() 

Do While Not bw.CancellationPending 
    Try 
     If Not sqliProcess.StandardOutput.EndOfStream Then 
      Debug.Print(sqliProcess.StandardOutput.ReadLine) 
     End If 
    Catch ex As Exception 
     MsgBox(ex.Message, MsgBoxStyle.Critical, "Error reading output") 
    End Try 

    Threading.Thread.Sleep(1) 
Loop 

哪個工作並打印出命令行程序的所有輸出。但是在某些時候命令行程序要求用戶交互,例如:

Type a number (1/2/3/4):

但在此之後的命令行程序停止。我懷疑這是因爲它沒有收到有效的選項。

有沒有一種方法來捕獲命令行程序需要用戶交互並持有流的閱讀能夠使用戶輸入的東西?

回答