Home
Manage Your Code
Snippet: Launching p4.exe (C#)
Title: Launching p4.exe Language: C#
Description: nothing exciting Views: 104
Author: Jesse Connell Date Added: 8/7/2008
Copy Code  
1{
2	System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("p4.exe", command);
3	startInfo.EnvironmentVariables["P4CLIENT"] = P4Client();
4	if (input != null)
5	{
6		startInfo.RedirectStandardInput = true;
7	}
8	startInfo.RedirectStandardOutput = true;
9	startInfo.UseShellExecute = false;
10	System.Diagnostics.Process proc = System.Diagnostics.Process.Start(startInfo);
11
12	if (input != null)
13	{
14		System.IO.StreamWriter writer = proc.StandardInput;
15		while (!input.EndOfStream)
16		{
17			string line = input.ReadLine();
18			writer.WriteLine(line);
19			Log(">>>" + line);
20		}
21		writer.Close();
22	}
23	System.IO.StreamReader reader = proc.StandardOutput;
24	while (!reader.EndOfStream)
25	{
26		string line = reader.ReadLine();
27		Log(line);
28		Console.WriteLine(line);
29	}
30
31	proc.WaitForExit();
32	if (proc.ExitCode != 0)
33	{
34		Log("Exit code = ", proc.ExitCode.ToString());
35	}
36}