@@ -32,7 +32,6 @@ public class GenerateGraphQLClient : Task
3232
3333 public override bool Execute ( )
3434 {
35- // Debugger.Launch();
3635 // list all source settings files
3736 // upldate this to include *.gql/*.graphql if/when i update it to support metadata in config file
3837 IEnumerable < ITaskItem > settings =
@@ -76,13 +75,34 @@ public override bool Execute()
7675 try
7776 {
7877 Directory . CreateDirectory ( tempFolder ) ;
79- Process process = Process . Start ( new ProcessStartInfo ( realexe , arguments )
78+ Process process = new Process
8079 {
81- UseShellExecute = false ,
82- CreateNoWindow = true ,
83- RedirectStandardOutput = true ,
84- RedirectStandardError = true
85- } ) ;
80+ StartInfo = new ProcessStartInfo ( realexe , arguments )
81+ {
82+ UseShellExecute = false ,
83+ CreateNoWindow = true ,
84+ RedirectStandardOutput = true ,
85+ RedirectStandardError = true
86+ } ,
87+ EnableRaisingEvents = true
88+ } ;
89+
90+ // we have to consume the output buffers otherwise they fill up
91+ // and the child process hangs.
92+ StringBuilder standardout = new StringBuilder ( ) ;
93+ StringBuilder errorout = new StringBuilder ( ) ;
94+ process . OutputDataReceived += ( s , e ) =>
95+ {
96+ standardout . AppendLine ( e . Data ) ;
97+ } ;
98+ process . ErrorDataReceived += ( s , e ) =>
99+ {
100+ errorout . AppendLine ( e . Data ) ;
101+ } ;
102+
103+ process . Start ( ) ;
104+ process . BeginOutputReadLine ( ) ;
105+ process . BeginErrorReadLine ( ) ;
86106
87107 // default timeout of 5 seconds
88108 int timeout = 5000 ;
@@ -106,7 +126,7 @@ public override bool Execute()
106126 return false ;
107127 }
108128
109- var errors = ( process . StandardError . ReadToEnd ( ) ?? "" ) . Trim ( ) ;
129+ var errors = errorout . ToString ( ) . Trim ( ) ;
110130 if ( ! string . IsNullOrWhiteSpace ( errors ) )
111131 {
112132 var errorLines = errors
@@ -139,7 +159,7 @@ public override bool Execute()
139159 return false ;
140160 }
141161
142- string filesoutput = process . StandardOutput . ReadToEnd ( ) ;
162+ string filesoutput = standardout . ToString ( ) ;
143163 this . Log . LogMessage ( MessageImportance . High , "generated = {0}" , filesoutput ) ;
144164
145165 IEnumerable < string > files = filesoutput
0 commit comments