@@ -183,34 +183,38 @@ impl AsyncCommandExecutor for tokio::process::Command {
183
183
/// Execute the command and return the stdout and stderr
184
184
async fn execute ( & mut self , timeout : Option < Duration > ) -> Result < ( String , String ) > {
185
185
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
- } ?;
190
186
let program = self . as_std ( ) . get_program ( ) . to_string_lossy ( ) . to_string ( ) ;
191
187
let stdout: String ;
192
188
let stderr: String ;
189
+ let status: ExitStatus ;
193
190
194
191
if OS == "windows" && program. as_str ( ) . ends_with ( "pg_ctl" ) {
195
192
// 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 ( ) ?;
196
197
stdout = String :: new ( ) ;
197
198
stderr = String :: new ( ) ;
199
+ status = process. wait ( ) . await ?;
198
200
} else {
201
+ let output = match timeout {
202
+ Some ( duration) => tokio:: time:: timeout ( duration, self . output ( ) ) . await ?,
203
+ None => self . output ( ) . await ,
204
+ } ?;
199
205
stdout = String :: from_utf8_lossy ( & output. stdout ) . into_owned ( ) ;
200
206
stderr = String :: from_utf8_lossy ( & output. stderr ) . into_owned ( ) ;
207
+ status = output. status ;
201
208
}
202
209
203
210
debug ! (
204
211
"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( ) ) ,
209
213
stdout,
210
214
stderr
211
215
) ;
212
216
213
- if output . status . success ( ) {
217
+ if status. success ( ) {
214
218
Ok ( ( stdout, stderr) )
215
219
} else {
216
220
Err ( Error :: CommandError { stdout, stderr } )
0 commit comments