-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShell.cs
64 lines (59 loc) · 2.09 KB
/
Shell.cs
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
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace Aida64_Esp8266_DisplayControler
{
#region Class Shell
public class Shell
{
#region Members
private string _filename;
private string _args;
private string _workdir;
private Process _process;
public string FileName { get { return this._filename; } }
public string Args { get { return this._args; } }
public string WorkDir { get { return this._workdir; } }
public bool HasExited { get { return this._process.HasExited; } }
#endregion
#region Constructor
public Shell(string filename, string args, string workdir, DataReceivedEventHandler OutputDataReceived, EventHandler ShellExited)
{
this._filename = filename;
this._args = args;
this._workdir = workdir;
this._process = new Process();
this._process.StartInfo.FileName = this._filename;
this._process.StartInfo.Arguments = this._args;
this._process.StartInfo.WorkingDirectory = this._workdir;
this._process.StartInfo.RedirectStandardOutput = true;
this._process.StartInfo.RedirectStandardError = true;
this._process.StartInfo.UseShellExecute = false;
this._process.StartInfo.CreateNoWindow = true;
this._process.EnableRaisingEvents = true;
this._process.OutputDataReceived += OutputDataReceived;
this._process.ErrorDataReceived += OutputDataReceived;
this._process.Exited += ShellExited;
}
#endregion
#region Methods
public void Start()
{
_process.Start();
this._process.BeginOutputReadLine();
this._process.BeginErrorReadLine();
}
public void Stop()
{
_process.Kill();
_process.CancelOutputRead();
_process.CancelErrorRead();
}
#endregion
}
#endregion
}