@@ -183,34 +183,38 @@ impl AsyncCommandExecutor for tokio::process::Command {
183183 /// Execute the command and return the stdout and stderr
184184 async fn execute ( & mut self , timeout : Option < Duration > ) -> Result < ( String , String ) > {
185185 debug ! ( "Executing command: {}" , self . to_command_string( ) ) ;
186- let output = match timeout {
187- Some ( duration) => tokio:: time:: timeout ( duration, self . output ( ) ) . await ?,
188- None => self . output ( ) . await ,
189- } ?;
190186 let program = self . as_std ( ) . get_program ( ) . to_string_lossy ( ) . to_string ( ) ;
191187 let stdout: String ;
192188 let stderr: String ;
189+ let status: ExitStatus ;
193190
194191 if OS == "windows" && program. as_str ( ) . ends_with ( "pg_ctl" ) {
195192 // The pg_ctl process can hang on Windows when attempting to get stdout/stderr.
193+ let mut process = self
194+ . stdout ( std:: process:: Stdio :: piped ( ) )
195+ . stderr ( std:: process:: Stdio :: piped ( ) )
196+ . spawn ( ) ?;
196197 stdout = String :: new ( ) ;
197198 stderr = String :: new ( ) ;
199+ status = process. wait ( ) . await ?;
198200 } else {
201+ let output = match timeout {
202+ Some ( duration) => tokio:: time:: timeout ( duration, self . output ( ) ) . await ?,
203+ None => self . output ( ) . await ,
204+ } ?;
199205 stdout = String :: from_utf8_lossy ( & output. stdout ) . into_owned ( ) ;
200206 stderr = String :: from_utf8_lossy ( & output. stderr ) . into_owned ( ) ;
207+ status = output. status ;
201208 }
202209
203210 debug ! (
204211 "Result: {}\n stdout: {}\n stderr: {}" ,
205- output
206- . status
207- . code( )
208- . map_or( "None" . to_string( ) , |c| c. to_string( ) ) ,
212+ status. code( ) . map_or( "None" . to_string( ) , |c| c. to_string( ) ) ,
209213 stdout,
210214 stderr
211215 ) ;
212216
213- if output . status . success ( ) {
217+ if status. success ( ) {
214218 Ok ( ( stdout, stderr) )
215219 } else {
216220 Err ( Error :: CommandError { stdout, stderr } )
0 commit comments