• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

how do I respond to the output of a dos program in a textbox

I have a subroutine that I use to capture the output of a dos program and display it in a textbox on a windows form.  This works great.  But sometimes the program wants a response.  How do I send this response?  I would like to simply type the response in the same textbox and hit enter.
Sub RunAntiVirus(ByVal Path As String, Optional ByVal Arguments As String = "")
        Using p As Process = New Process
            p.StartInfo.FileName = Path
            p.StartInfo.UseShellExecute = False
            p.StartInfo.Arguments = Arguments
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            p.StartInfo.CreateNoWindow = True
            p.StartInfo.RedirectStandardOutput = True
            p.StartInfo.RedirectStandardInput = True

            p.Start()

            Dim SR As System.IO.StreamReader = p.StandardOutput

            While Not p.HasExited
                Do Until SR.EndOfStream = True
                    rtb1.AppendText(SR.ReadLine & vbNewLine)
                Loop
                System.Threading.Thread.Sleep(5000)
            End While
            My.Computer.FileSystem.WriteAllText("MASLog", rtb1.Text & vbNewLine & vbNewLine, True)
        End Using

    End Sub

Open in new window

0
NevSoFly
Asked:
NevSoFly
  • 2
  • 2
1 Solution
 
Jaime OlivaresCommented:
declare a variable for your standar input:
Dim SW As System.IO.StreamWriter = p.StandardInput

and send information using regular StreamWriter methods.
0
 
NevSoFlyAuthor Commented:
So it would look something like this?
            Dim SW As System.IO.StreamWriter = p.StandardInput
            SW.Write("Helo")

Is there anyway of telling when the process is awaiting a response from the user?
0
 
Jaime OlivaresCommented:
Is there anyway of telling when the process is awaiting a response from the user?
I don't think so, you should parse the prompt messages from the console application.
Also consider that the application should be reading input from the StandardInput (OS stream) and not using a direct keyboard reading technique.
0
 
NevSoFlyAuthor Commented:
thank you.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now