C# Command Prompt Reading

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 27
Reputation: DevC++4.9.9.2 is an unknown quantity at this point 
Solved Threads: 1
DevC++4.9.9.2 DevC++4.9.9.2 is offline Offline
Light Poster

C# Command Prompt Reading

 
0
  #1
May 12th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,631
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 470
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: C# Command Prompt Reading

 
0
  #2
May 12th, 2009
Use the following code :

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication5
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string s = "";
  13. Sample a = new Sample();
  14. a.Refresh(); // re-paint a form
  15. do
  16. {
  17. s = Console.ReadLine();
  18. a.MyText = s;
  19. a.Refresh(); // re-paint a form
  20. } while (s.Length != 0);
  21. }
  22. static void show()
  23. {
  24.  
  25. }
  26. }
  27. }
  28.  
  29. class Sample : System.Windows.Forms.Form
  30. {
  31. System.Windows.Forms.TextBox t = new System.Windows.Forms.TextBox();
  32. public Sample()
  33. {
  34. t.Multiline = true;
  35. t.Size = new System.Drawing.Size(100, 100);
  36. Controls.Add(t);
  37. Show();
  38. }
  39. public string MyText
  40. {
  41. get
  42. {
  43. return t.Text;
  44. }
  45. set
  46. {
  47. t.Text = t.Text + "\r" + "\n" + value;
  48. }
  49. }
  50.  
  51. }
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 27
Reputation: DevC++4.9.9.2 is an unknown quantity at this point 
Solved Threads: 1
DevC++4.9.9.2 DevC++4.9.9.2 is offline Offline
Light Poster

Re: C# Command Prompt Reading

 
0
  #3
May 13th, 2009
Thank you, works perfect.


Originally Posted by adatapost View Post
Use the following code :

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication5
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string s = "";
  13. Sample a = new Sample();
  14. a.Refresh(); // re-paint a form
  15. do
  16. {
  17. s = Console.ReadLine();
  18. a.MyText = s;
  19. a.Refresh(); // re-paint a form
  20. } while (s.Length != 0);
  21. }
  22. static void show()
  23. {
  24.  
  25. }
  26. }
  27. }
  28.  
  29. class Sample : System.Windows.Forms.Form
  30. {
  31. System.Windows.Forms.TextBox t = new System.Windows.Forms.TextBox();
  32. public Sample()
  33. {
  34. t.Multiline = true;
  35. t.Size = new System.Drawing.Size(100, 100);
  36. Controls.Add(t);
  37. Show();
  38. }
  39. public string MyText
  40. {
  41. get
  42. {
  43. return t.Text;
  44. }
  45. set
  46. {
  47. t.Text = t.Text + "\r" + "\n" + value;
  48. }
  49. }
  50.  
  51. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC