Advertisement
NikolaDimitroff

Reading Console.Out

Aug 5th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. static void Main(string[] args)
  2.         {
  3.             if (args.Length == 0)
  4.             {
  5.                 // Now start another instance and read from it
  6.                 ProcessStartInfo info = new ProcessStartInfo();
  7.                 // Set some important properties
  8.                 info.RedirectStandardOutput = true;
  9.                 info.UseShellExecute = false;
  10.                 info.FileName = System.AppDomain.CurrentDomain.FriendlyName;
  11.                 // Random arguments string
  12.                 info.Arguments = "some arguments to differentiate the 2 usages";
  13.                 // Start the process, wait to end, read from it
  14.                 Process process = Process.Start(info);
  15.                 process.WaitForExit();
  16.                 Console.WriteLine(process.StandardOutput.ReadToEnd());
  17.             }
  18.             else
  19.             {
  20.                 // If the process was started with arguments, then run the part that we wish to read from
  21.                 Console.WriteLine("called with arguments");
  22.             }
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement