Solved

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

Posted on 2010-11-10
4
339 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now