Skip to content

Instantly share code, notes, and snippets.

@SamWM
Created December 4, 2012 17:51
Show Gist options
  • Save SamWM/4206819 to your computer and use it in GitHub Desktop.
Save SamWM/4206819 to your computer and use it in GitHub Desktop.
Launch Other Processes (C#)
void Main()
{
Process p = new Process();
p.EnableRaisingEvents = true;
ProcessStartInfo pi = new ProcessStartInfo { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, FileName = "cmd.exe", Arguments = "/c dir /w" };
p.Exited += delegate {
Console.WriteLine("--ExitCode--" + Environment.NewLine + p.ExitCode);
Console.WriteLine("--StandardOutput--" + Environment.NewLine + p.StandardOutput.ReadToEnd());
Console.WriteLine("--StandardError--" + Environment.NewLine + p.StandardError.ReadToEnd());
};
p.StartInfo = pi;
p.Start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment