Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 5aeb275

Browse files
Fixing conditionals
1 parent 83bb4c5 commit 5aeb275

File tree

1 file changed

+41
-47
lines changed

1 file changed

+41
-47
lines changed

src/GitHub.Api/NewTaskSystem/ProcessTask.cs

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,6 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor,
7878

7979
public void Run()
8080
{
81-
if (!Process.StartInfo.RedirectStandardOutput)
82-
{
83-
throw new ArgumentException("Process must RedirectStandardOutput");
84-
}
85-
86-
if (!Process.StartInfo.RedirectStandardError)
87-
{
88-
throw new ArgumentException("Process must RedirectStandardError");
89-
}
90-
91-
if (!Process.StartInfo.CreateNoWindow)
92-
{
93-
throw new ArgumentException("Process must CreateNoWindow");
94-
}
95-
9681
try
9782
{
9883
Process.Start();
@@ -120,48 +105,57 @@ public void Run()
120105

121106
onStart?.Invoke();
122107

123-
var outputStream = Process.StandardOutput;
124-
var line = outputStream.ReadLine();
125-
while (line != null)
108+
if (Process.StartInfo.CreateNoWindow)
126109
{
127-
outputProcessor.LineReceived(line);
128-
129-
if (token.IsCancellationRequested)
110+
if (Process.StartInfo.RedirectStandardOutput)
130111
{
131-
if (!Process.HasExited)
132-
Process.Kill();
112+
var outputStream = Process.StandardOutput;
113+
var line = outputStream.ReadLine();
114+
while (line != null)
115+
{
116+
outputProcessor.LineReceived(line);
133117

134-
Process.Close();
135-
onEnd?.Invoke();
136-
token.ThrowIfCancellationRequested();
137-
}
118+
if (token.IsCancellationRequested)
119+
{
120+
if (!Process.HasExited)
121+
Process.Kill();
138122

139-
line = outputStream.ReadLine();
140-
}
141-
outputProcessor.LineReceived(null);
123+
Process.Close();
124+
onEnd?.Invoke();
125+
token.ThrowIfCancellationRequested();
126+
}
142127

143-
var errorStream = Process.StandardError;
144-
var errorLine = errorStream.ReadLine();
145-
while (errorLine != null)
146-
{
147-
errors.Add(errorLine);
128+
line = outputStream.ReadLine();
129+
}
130+
outputProcessor.LineReceived(null);
131+
}
148132

149-
if (token.IsCancellationRequested)
133+
if (!Process.StartInfo.RedirectStandardError)
150134
{
151-
if (!Process.HasExited)
152-
Process.Kill();
135+
var errorStream = Process.StandardError;
136+
var errorLine = errorStream.ReadLine();
137+
while (errorLine != null)
138+
{
139+
errors.Add(errorLine);
153140

154-
Process.Close();
155-
onEnd?.Invoke();
156-
token.ThrowIfCancellationRequested();
157-
}
141+
if (token.IsCancellationRequested)
142+
{
143+
if (!Process.HasExited)
144+
Process.Kill();
158145

159-
errorLine = errorStream.ReadLine();
160-
}
146+
Process.Close();
147+
onEnd?.Invoke();
148+
token.ThrowIfCancellationRequested();
149+
}
161150

162-
if (Process.ExitCode != 0 && errors.Count > 0)
163-
{
164-
onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray()));
151+
errorLine = errorStream.ReadLine();
152+
}
153+
154+
if (Process.ExitCode != 0 && errors.Count > 0)
155+
{
156+
onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray()));
157+
}
158+
}
165159
}
166160

167161
onEnd?.Invoke();

0 commit comments

Comments
 (0)