| | |
C# Command Prompt Reading
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 27
Reputation:
Solved Threads: 1
I am trying to read a line from the command prompt and output that line to a text box in my C# application. The only catch is i can't seem to get it to read a line at a time and display it in the text box as the command prompt is running its command.
for example
string output = "";
while (output != null)
{
output = console.StandardOutput.ReadLine();
OutputBox.Text += '\n' + output;
}
Does anyone know how to read a command prompt line by line and output it into a text box as it is occurring?
for example
string output = "";
while (output != null)
{
output = console.StandardOutput.ReadLine();
OutputBox.Text += '\n' + output;
}
Does anyone know how to read a command prompt line by line and output it into a text box as it is occurring?
Use the following code :
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { string s = ""; Sample a = new Sample(); a.Refresh(); // re-paint a form do { s = Console.ReadLine(); a.MyText = s; a.Refresh(); // re-paint a form } while (s.Length != 0); } static void show() { } } } class Sample : System.Windows.Forms.Form { System.Windows.Forms.TextBox t = new System.Windows.Forms.TextBox(); public Sample() { t.Multiline = true; t.Size = new System.Drawing.Size(100, 100); Controls.Add(t); Show(); } public string MyText { get { return t.Text; } set { t.Text = t.Text + "\r" + "\n" + value; } } }
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Apr 2008
Posts: 27
Reputation:
Solved Threads: 1
Thank you, works perfect.
•
•
•
•
Use the following code :
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { string s = ""; Sample a = new Sample(); a.Refresh(); // re-paint a form do { s = Console.ReadLine(); a.MyText = s; a.Refresh(); // re-paint a form } while (s.Length != 0); } static void show() { } } } class Sample : System.Windows.Forms.Form { System.Windows.Forms.TextBox t = new System.Windows.Forms.TextBox(); public Sample() { t.Multiline = true; t.Size = new System.Drawing.Size(100, 100); Controls.Add(t); Show(); } public string MyText { get { return t.Text; } set { t.Text = t.Text + "\r" + "\n" + value; } } }
![]() |
Similar Threads
- XP command prompt (Windows NT / 2000 / XP)
- Command Prompt and Visual Basic (Visual Basic 4 / 5 / 6)
- Command Prompt Question (Windows NT / 2000 / XP)
- getting around spaces in windows command prompt commands (Windows NT / 2000 / XP)
- I can't compile from command prompt (Java)
- Viewing An IP Address in Command Prompt (Windows NT / 2000 / XP)
- executing the windows command prompt (C++)
- Command Prompt Text Color Help (Windows NT / 2000 / XP)
- Command Prompt (Windows Software)
- Change background color of command prompt (Windows tips 'n' tweaks)
Other Threads in the C# Forum
- Previous Thread: Thread
- Next Thread: open folder
| Thread Tools | Search this Thread |
.net access algorithm angle array barchart bitmap box broadcast buttons c# capturing check checkbox client combobox control conversion convert csharp custom database datagrid datagridview dataset datetime dbconnection degrees delegate development disappear draganddrop drawing encryption enum event excel file firefox form format forms function gdi+ httpwebrequest image index input install java label leak libraries list listbox mandelbrot math monodevelop mouseclick msword mysql operator path pause photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox round server sleep socket sql statistics stream string table tcpclientchannel text textbox thread time timer update usercontrol validation virtualization visualbasic visualstudio webbrowser windows winforms wpf xml






