@@ -107,7 +107,7 @@ private async Task<CommandResult> ExecuteAsyncInternal(string executable, string
107107 {
108108 var output = new List < string > ( ) ;
109109 CurrentProcess = CreateProcess ( executable , args ) ;
110- CurrentProcess . ErrorDataReceived + = ( s , e ) =>
110+ DataReceivedEventHandler errorHandler = ( s , e ) =>
111111 {
112112 if ( e . Data == null )
113113 return ;
@@ -118,7 +118,7 @@ private async Task<CommandResult> ExecuteAsyncInternal(string executable, string
118118 ErrorDataReceived ? . Invoke ( s , e ) ;
119119 } ;
120120
121- CurrentProcess . OutputDataReceived + = ( s , e ) =>
121+ DataReceivedEventHandler outputHandler = ( s , e ) =>
122122 {
123123 if ( e . Data == null )
124124 return ;
@@ -129,11 +129,17 @@ private async Task<CommandResult> ExecuteAsyncInternal(string executable, string
129129 OutputDataReceived ? . Invoke ( s , e ) ;
130130 } ;
131131
132+ CurrentProcess . ErrorDataReceived += errorHandler ;
133+ CurrentProcess . OutputDataReceived += outputHandler ;
134+
132135 var completionTask = CurrentProcess . StartAndWaitForExitAsync ( ) ;
133136 CurrentProcess . BeginOutputReadLine ( ) ;
134137 CurrentProcess . BeginErrorReadLine ( ) ;
135138 await completionTask ;
136139
140+ CurrentProcess . ErrorDataReceived -= errorHandler ;
141+ CurrentProcess . OutputDataReceived -= outputHandler ;
142+
137143 RemoveNullTerminator ( output ) ;
138144
139145 return new CommandResult (
0 commit comments