@@ -24,9 +24,9 @@ public class RunProgramTask : TaskBase<int, IRunProgramTask>, IRunProgramTask
2424
2525 private string _workingFolder ;
2626
27- private bool _captureOutput ;
27+ private bool _captureOutput = true ;
2828
29- private bool _captureErrorOutput ;
29+ private bool _captureErrorOutput = true ;
3030
3131 private LogLevel _outputLogLevel = LogLevel . Info ;
3232
@@ -110,13 +110,27 @@ public IRunProgramTask CaptureOutput()
110110 return this ;
111111 }
112112
113+ /// <inheritdoc />
114+ public IRunProgramTask CaptureOutput ( bool capture )
115+ {
116+ _captureOutput = capture ;
117+ return this ;
118+ }
119+
113120 /// <inheritdoc />
114121 public IRunProgramTask CaptureErrorOutput ( )
115122 {
116123 _captureErrorOutput = true ;
117124 return this ;
118125 }
119126
127+ /// <inheritdoc />
128+ public IRunProgramTask CaptureErrorOutput ( bool capture )
129+ {
130+ _captureErrorOutput = false ;
131+ return this ;
132+ }
133+
120134 /// <inheritdoc />
121135 /// <summary>
122136 /// Get the output produced by executable.
@@ -222,25 +236,35 @@ protected override int DoExecute(ITaskContextInternal context)
222236 ICommand command = _commandFactory . Create ( cmd , _arguments . Select ( x => x . arg ) ) ;
223237 string workingFolder = _workingFolder ?? rootDir ;
224238 command
225- . CaptureStdErr ( )
226- . CaptureStdOut ( )
227- . WorkingDirectory ( workingFolder )
228- . OnErrorLine ( l =>
229- {
230- if ( _outputLogLevel >= LogLevel . Error )
231- DoLogInfo ( l ) ;
239+ . WorkingDirectory ( workingFolder ) ;
232240
233- if ( _captureErrorOutput )
234- _errorOutput . AppendLine ( l ) ;
235- } )
236- . OnOutputLine ( l =>
237- {
238- if ( _outputLogLevel >= LogLevel . Info )
239- DoLogInfo ( l ) ;
241+ if ( _captureOutput )
242+ {
243+ command
244+ . CaptureStdOut ( )
245+ . OnOutputLine ( l =>
246+ {
247+ if ( _outputLogLevel >= LogLevel . Info )
248+ DoLogInfo ( l ) ;
249+
250+ if ( _captureOutput )
251+ _output . AppendLine ( l ) ;
252+ } ) ;
253+ }
240254
241- if ( _captureOutput )
242- _output . AppendLine ( l ) ;
243- } ) ;
255+ if ( _captureErrorOutput )
256+ {
257+ command
258+ . CaptureStdErr ( )
259+ . OnErrorLine ( l =>
260+ {
261+ if ( _outputLogLevel >= LogLevel . Error )
262+ DoLogInfo ( l ) ;
263+
264+ if ( _captureErrorOutput )
265+ _errorOutput . AppendLine ( l ) ;
266+ } ) ;
267+ }
244268
245269 string commandArgs = null ;
246270 ProcessAdditionalOptions ( context ) ;
0 commit comments