|
-
May 27th, 2010, 12:55 AM
#10
Re: Running a DOS command, and show output in textbox, realtime?
Actually you don't need to redraw your form.
The txtConsoleIn and txtConsoleOut textboxes are just for example.
If you need only to display the output of a command you a) don't need txtConsoleIn at all and b) this example shows how to receive data from the command's standard output stream (see Async_Data_Received sub). This sub is invoked each time the command sends something to its standard output stream (and e.Data will hold the string it 'displayed'). Having received this event you simply use this text as you see fit (it's in another thread so you should invoke a sub in the UI thread to manipulate your controls - that's why you need to invoke Sync_Output sub and pass the output text to it). In the Sync_Output sub you simply display the received text in the textbox while you can do something different.
Here's how it works.
1. I start a process and assign an EventHandler for its OutputDataReceived event so each time this command sends something to its' StdOut your programm will be notified.
2. If something is received the Async_Data_Received handler is invoked.
3. It invokes a syncronous with the UI Sync_Output and passes the data it has just received to it.
4. In the Sync_Output you can do whatever you want with the text - display it, parse it, etc.
5. To exit this particular app you need to type Exit but if you run some other command it will exit as soon as the execution finishes.
You need to change "cmd.exe" to "tracert" and pass "www.bbc.co.uk" as its argument and then remove all code for txtConsoleIn, that's all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|