Advertisement
Guest User

Untitled

a guest
Sep 1st, 2012
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1.                         string PS_path = name;
  2.                         System.Diagnostics.Process ps = new System.Diagnostics.Process();
  3.                         ps.StartInfo.CreateNoWindow = false;
  4.                         ps.StartInfo.FileName = PS_path;
  5.                         string argStr = "";
  6.                         for (int i = 1; i < args.Length; i++)
  7.                         {
  8.                             argStr += args[i] + " ";
  9.                         }
  10.                         ps.StartInfo.Arguments = argStr;
  11.                         ps.StartInfo.RedirectStandardError = true;
  12.                         ps.StartInfo.RedirectStandardInput = true;
  13.                         ps.StartInfo.RedirectStandardOutput = true;
  14.                         ps.StartInfo.UseShellExecute = false;
  15.                         ps.Start();
  16.                        
  17.                         string oldOutput="";
  18.                         string oldError="";
  19.                         StreamReader input = new StreamReader(Console.OpenStandardInput());
  20.                         while (!ps.HasExited)
  21.                         {
  22.                             string line;
  23.                             line = ps.StandardOutput.ReadLine();
  24.                             if (line != null)
  25.                                 Console.WriteLine(line);
  26.  
  27.                             line = ps.StandardError.ReadLine();
  28.                             if (line != null)
  29.                                 Console.Error.WriteLine(line);
  30.                         }
  31.  
  32.  
  33.                         if (ps.ExitCode != 0)
  34.                         {
  35.                             Console.ReadKey();
  36.                         }
  37.                         System.Environment.Exit(ps.ExitCode);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement