forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessOutputStreamReader.cs
More file actions
70 lines (70 loc) · 1.39 KB
/
Copy pathProcessOutputStreamReader.cs
File metadata and controls
70 lines (70 loc) · 1.39 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace UnityEditor.Utils
{
internal class ProcessOutputStreamReader
{
private readonly Func<bool> hostProcessExited;
private readonly StreamReader stream;
internal List<string> lines;
private Thread thread;
internal ProcessOutputStreamReader(Process p, StreamReader stream) : this(() => p.HasExited, stream)
{
}
internal ProcessOutputStreamReader(Func<bool> hostProcessExited, StreamReader stream)
{
this.hostProcessExited = hostProcessExited;
this.stream = stream;
this.lines = new List<string>();
this.thread = new Thread(new ThreadStart(this.ThreadFunc));
this.thread.Start();
}
private void ThreadFunc()
{
if (this.hostProcessExited())
{
return;
}
while (this.stream.BaseStream != null)
{
string text = this.stream.ReadLine();
if (text == null)
{
return;
}
List<string> obj = this.lines;
Monitor.Enter(obj);
try
{
this.lines.Add(text);
}
finally
{
Monitor.Exit(obj);
}
}
}
internal string[] GetOutput()
{
if (this.hostProcessExited())
{
this.thread.Join();
}
List<string> obj = this.lines;
Monitor.Enter(obj);
string[] result;
try
{
result = this.lines.ToArray();
}
finally
{
Monitor.Exit(obj);
}
return result;
}
}
}