Solved

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

10 Experts available now in Live!

Get 1:1 Help Now