Solved

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

Posted on 2010-11-10
4
343 Views
Last Modified: 2012-05-10
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
Comment
Question by:NevSoFly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 34109371
declare a variable for your standar input:
Dim SW As System.IO.StreamWriter = p.StandardInput

and send information using regular StreamWriter methods.
0
 

Author Comment

by:NevSoFly
ID: 34114333
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
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 34115071
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
 

Author Closing Comment

by:NevSoFly
ID: 34122106
thank you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question