-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProcessHandler.cs
More file actions
56 lines (50 loc) · 1.84 KB
/
ProcessHandler.cs
File metadata and controls
56 lines (50 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Diagnostics;
using System.IO;
namespace StarterModel
{
/// <summary>
/// Wrapper Class for the Process, handles all the process configurations and Life Cycle.
/// </summary>
public class ProcessHandler
{
protected string name;
protected string arguments;
protected bool redirectOutput = true;
protected bool shellExecute = false;
protected bool createNoWindow = true;
protected Process process;
public Process Process { get { return process; } }
public string Name { get { return name; } }
public ProcessHandler(string name, string arguments, bool redirectOutput, bool shellExecute, bool createNoWindow)
{
this.name = name;
this.arguments = arguments;
this.redirectOutput = redirectOutput;
this.shellExecute = shellExecute;
this.createNoWindow = createNoWindow;
process = new Process();
}
public ProcessHandler(string name, string arguments)
{
this.name = name;
this.arguments = arguments;
process = new Process();
}
/// <summary>
/// Create the process with the given configurations.
/// </summary>
public void CreateProcess()
{
process.StartInfo.FileName = name;
process.StartInfo.Arguments = arguments;
process.StartInfo.RedirectStandardOutput = redirectOutput;
process.StartInfo.RedirectStandardError = redirectOutput;
process.StartInfo.CreateNoWindow = createNoWindow;
process.StartInfo.WorkingDirectory = Path.GetDirectoryName(name);
process.StartInfo.UseShellExecute = shellExecute;
process.EnableRaisingEvents = true;
process.Start();
}
}
}