Question How to get output from cmd like window into textbox

Da9L

New member
Joined
Feb 10, 2011
Messages
1
Programming Experience
Beginner
Hello there !

First of all i would like to clarify that iam ABSOLUTE beginner at VB.Net ! Iam using Visual Basic 2010 Express edition and have only been doing that for the last few days..

What iam trying to make is an app that would automaticly start two other applications, where one of them needs a single key pressed as input, and copy some link to the clipboard.

I've allready acomplished the mentioned but i want to do one more thing

The application that needs some keys pressed in order to start is this LINK

As you can see it looks like some CMD piece of application.

i want the output from that window into a TextBox on my form, but have been unable to do that.

Ive tried two methods allready.. The most described and used is the RedirectStandardOutput and RedirectStandardInput methods:

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim p As New Process
        RichTextBox1.Text = "* - Starting Modern Warfare 2 Server Admin Tool"
        p.StartInfo.FileName = ("mw2sa.exe")
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.StartInfo.RedirectStandardInput = True
        p.StartInfo.CreateNoWindow = False
        AddHandler p.OutputDataReceived, AddressOf HelloMum
        p.Start()
        p.BeginOutputReadLine()
        System.Threading.Thread.Sleep(1000) 'time given to the program to launch and be ready for input
        Dim SW As System.IO.StreamWriter = p.StandardInput
        SW.Write("1")
    End Sub

     Sub HelloMum(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
        UpdateTextBox(e.Data)
    End Sub
However i can only get the output to work. Input does not seem to get to the program.

Then i thought of another method which was by exporting the content of the cmd window (in this case the mw2sa.exe window) to a textfile every few seconds and then read that textfile into my textbox. This would also benefit for some few reasons:

1. If i launch the program via the

VB.NET:
ProcID = Shell("mw2sa.exe, AppWinStyle.NormalFocus)
iam able to send input to the program via

VB.NET:
My.Computer.Keyboard.SendKeys("1", True)
2. This would also store a "log" as the textfile for later use.

However the tricky part for me is to:

1. Get the output from the mw2sa.exe window to automaticly update the textfile every few seconds

2. Be able to read the textfile in the textbox. VB tells me its unable to read the textfile as it is beeing used.

3. Somehow if i use the

VB.NET:
ProcID = Shell("cmd /K mw2sa.exe > log.txt", AppWinStyle.NormalFocus)
To launch the program all i get is a black cmd window.. However, a log.txt file is created with the correct output, but since the cmd window isnt showing any output i dont think im able to use sendkeys to start the program. And if i try with only

VB.NET:
ProcID = Shell("mw2sa.exe > log.txt", AppWinStyle.NormalFocus)
I get the correct cmd window with all the right output. Sendkeys is also able to pass the key to start the program... But no log.txt is created!

I hope all this is understandable as iam not that good at english! If not please ask and i will try to clarify !

And i hope you can help me.. :)

Thanks a lot !

~D
 
Last edited:

Latest posts

Back
Top