开发者

Respond to commandline program question in VB.net

I'm using VB.net to have a GUI on top of a commandline program.

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

Which works and prints out all output from the commandline program. However at some point the commandline program ask for us开发者_高级运维er interaction, eg:

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

But the commandline program stops after this. I suspect this is because it doesn't receive a valid option.

Is there a way to capture when the commandline program wants user interaction and hold the reading of the stream to be able to enable the user to input something?


It's not that hard if you use the events. (Don't forget EnableRaisingEvents). Look here at outputdatareceived..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜