@@ -78,21 +78,6 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor,
78
78
79
79
public void Run ( )
80
80
{
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
-
96
81
try
97
82
{
98
83
Process . Start ( ) ;
@@ -120,48 +105,57 @@ public void Run()
120
105
121
106
onStart ? . Invoke ( ) ;
122
107
123
- var outputStream = Process . StandardOutput ;
124
- var line = outputStream . ReadLine ( ) ;
125
- while ( line != null )
108
+ if ( Process . StartInfo . CreateNoWindow )
126
109
{
127
- outputProcessor . LineReceived ( line ) ;
128
-
129
- if ( token . IsCancellationRequested )
110
+ if ( Process . StartInfo . RedirectStandardOutput )
130
111
{
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 ) ;
133
117
134
- Process . Close ( ) ;
135
- onEnd ? . Invoke ( ) ;
136
- token . ThrowIfCancellationRequested ( ) ;
137
- }
118
+ if ( token . IsCancellationRequested )
119
+ {
120
+ if ( ! Process . HasExited )
121
+ Process . Kill ( ) ;
138
122
139
- line = outputStream . ReadLine ( ) ;
140
- }
141
- outputProcessor . LineReceived ( null ) ;
123
+ Process . Close ( ) ;
124
+ onEnd ? . Invoke ( ) ;
125
+ token . ThrowIfCancellationRequested ( ) ;
126
+ }
142
127
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
+ }
148
132
149
- if ( token . IsCancellationRequested )
133
+ if ( ! Process . StartInfo . RedirectStandardError )
150
134
{
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 ) ;
153
140
154
- Process . Close ( ) ;
155
- onEnd ? . Invoke ( ) ;
156
- token . ThrowIfCancellationRequested ( ) ;
157
- }
141
+ if ( token . IsCancellationRequested )
142
+ {
143
+ if ( ! Process . HasExited )
144
+ Process . Kill ( ) ;
158
145
159
- errorLine = errorStream . ReadLine ( ) ;
160
- }
146
+ Process . Close ( ) ;
147
+ onEnd ? . Invoke ( ) ;
148
+ token . ThrowIfCancellationRequested ( ) ;
149
+ }
161
150
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
+ }
165
159
}
166
160
167
161
onEnd ? . Invoke ( ) ;
0 commit comments