|
-
Jan 20th, 2009, 04:38 PM
#1
Re: Automate Command Prompt Window (CMD), Redirect Output to Application [2003/2005]
This is one of the most useful pieces of code I have come across in the Codebank.
A quick question: The code in post #10 always clears the TextBox first, then updates it with the results of the next command. How could this 'clear first' be inhibited, so the TextBox shows continuous output, as a normal cmd would do?
Post #10 has an error, because it exits prematurely, before reading the content. Take a quick look at post #14, but run your own command.
Do you want the window not to exit? You don't have to command the exit.
How many commands do you wish to run?
You could append the textbox after each command, by doing something like this:
Code:
SW.WriteLine("A command here")
TextBox1.Text &= SR.ReadToEnd
SW.WriteLine("Another command here")
TextBox1.Text &= SR.ReadToEnd
-
Jan 20th, 2009, 05:46 PM
#2
Junior Member
Re: Automate Command Prompt Window (CMD), Redirect Output to Application [2003/2005]
I solved the clear first problem by changing:
Code:
Private Sub CMDAutomateThread()
txtResults.Text = Results
End Sub
to
Code:
Private Sub UpdateText()
txtResults.AppendText(Results)
txtResults.SelectionStart = txtResults.Text.Length ' this line and the next
txtResults.ScrollToCaret() 'sets the scrollbar to the bottom
End Sub
I also wanted to see the latest data in the textbox, and scroll back to see older data, hence the other two lines of code.
I do not want the cmd window to close, I want it, and 5 others, to stay open. I am adapting this code to open 6 server windows (cmd-like) as part of a GUI for a Virtual World (here is the work-in-progress)
My textboxes should act in the same way as these server (cmd console) windows, i.e. I can see all status messages, and I can enter commands and see the results.
While testing, I will send commands in the way the code in this thread uses, but later I will change it to specific commands behind button clicks, or Menu options.
I am currently working on a way to set a rolling buffer size for the TextBox, so it does not get too big.
Your alternative code in post #14 looks very interesting indeed. I will have a play with that tomorrow.
Rock
-
Jan 24th, 2009, 08:41 AM
#3
Junior Member
Re: Automate Command Prompt Window (CMD), Redirect Output to Application [2003/2005]
I am a little bit confused about the purpose of the following line in the code:
SW.Writeline("exit")
What is this line for? The comment says 'exits command prompt window, but does this mean that the cmd window is now closed, or what?
What I need is for the cmd window to remain open at all times, displaying its messages in my TextBox, accepting and executing commands, and displaying the results, until I close the application.
What do I need to do to the code to achieve this?
TIA
Rock
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
|