code_junkie

C# Console receive input with pipe

Nov 11th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. string s;
  6. while ((s = Console.ReadLine()) != null)
  7. {
  8. Console.WriteLine(s);
  9. }
  10.  
  11. }
  12. }
  13.  
  14. public static void Main(String[] args)
  15. {
  16.  
  17. String pipedText = "";
  18. bool isKeyAvailable;
  19.  
  20. try
  21. {
  22. isKeyAvailable = System.Console.KeyAvailable;
  23. }
  24. catch (InvalidOperationException expected)
  25. {
  26. pipedText = System.Console.In.ReadToEnd();
  27. }
  28.  
  29. //do something with pipedText or the args
  30. }
  31.  
  32. public static void Main(String[] args)
  33. {
  34.  
  35. String pipedText = "";
  36. bool isKeyAvailable;
  37.  
  38. try
  39. {
  40. isKeyAvailable = System.Console.KeyAvailable;
  41. }
  42. catch (InvalidOperationException expected)
  43. {
  44. pipedText = System.Console.In.ReadToEnd();
  45. }
  46.  
  47. //do something with pipedText or the args
  48. }
  49.  
  50. while ((s = Console.ReadLine()) != null)
Add Comment
Please, Sign In to add comment