Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7. using System.Diagnostics;
  8.  
  9. namespace BLConsole
  10. {
  11. class Program
  12. {
  13. public static Process p;
  14.  
  15. static void Main(string[] args)
  16. {
  17. AppDomain.CurrentDomain.ProcessExit += new EventHandler(onProcessExit);
  18. Console.Title = "BL Console";
  19.  
  20. p = new Process();
  21. ProcessStartInfo si = new ProcessStartInfo();
  22.  
  23. //Start info properties
  24. si.FileName = "C:\\Users\\Adam\\Documents\\Blockland\\Blockland.exe";
  25. si.Arguments = "ptlaaxobimwroe";
  26. si.UseShellExecute = false;
  27. si.RedirectStandardOutput = true;
  28. si.RedirectStandardInput = true;
  29. si.CreateNoWindow = true;
  30. si.WindowStyle = ProcessWindowStyle.Hidden;
  31. p.StartInfo = si;
  32. p.Start();
  33.  
  34.  
  35. //Start new thread for output
  36. Thread t = new Thread(OutputThread);
  37. t.Start();
  38.  
  39. //Accept input
  40. String input = "";
  41. while(input != "stop")
  42. {
  43. input = Console.ReadLine();
  44. Console.WriteLine("You entered " + input);
  45. p.StandardInput.WriteLine(input);
  46. }
  47. onProcessExit(null, null);
  48. }
  49.  
  50. static void onProcessExit(object sender, EventArgs e)
  51. {
  52. p.Kill();
  53. }
  54.  
  55. static void OutputThread()
  56. {
  57. while (true)
  58. {
  59. while (!p.StandardOutput.EndOfStream)
  60. {
  61. Console.WriteLine(p.StandardOutput.ReadLine());
  62. }
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement