| | |
C# Command Prompt Reading
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 30
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; } } }
•
•
Join Date: Apr 2008
Posts: 30
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
Views: 1498 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast button buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development drawing encryption enum event excel file files form format ftp function gdi+ http httpwebrequest image index input install java label list listbox login mandelbrot math mouseclick mysql networking object oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view webbrowser windows winforms wpf xml






