Solved

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

Posted on 2010-11-10
4
342 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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 Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

732 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