1- use crate :: local_logger:: suspend_progress_bar;
21use crate :: prelude:: * ;
3- use crate :: run:: runner:: EXECUTOR_TARGET ;
42use std:: future:: Future ;
5- use std:: io:: { Read , Write } ;
6- use std:: process:: Command ;
73use std:: process:: ExitStatus ;
8- use std :: thread ;
4+ use tokio :: process :: Command ;
95
106/// Run a command and log its output to stdout and stderr
117///
@@ -25,49 +21,52 @@ where
2521 F : FnOnce ( u32 ) -> Fut ,
2622 Fut : Future < Output = anyhow:: Result < ( ) > > ,
2723{
28- fn log_tee (
29- mut reader : impl Read ,
30- mut writer : impl Write ,
31- log_prefix : Option < & str > ,
32- ) -> Result < ( ) > {
33- let prefix = log_prefix. unwrap_or ( "" ) ;
34- let mut buffer = [ 0 ; 1024 ] ;
35- loop {
36- let bytes_read = reader. read ( & mut buffer) ?;
37- if bytes_read == 0 {
38- break ;
39- }
40- suspend_progress_bar ( || {
41- writer. write_all ( & buffer[ ..bytes_read] ) . unwrap ( ) ;
42- trace ! (
43- target: EXECUTOR_TARGET ,
44- "{}{}" ,
45- prefix,
46- String :: from_utf8_lossy( & buffer[ ..bytes_read] )
47- ) ;
48- } ) ;
49- }
50- Ok ( ( ) )
51- }
24+ // fn log_tee(
25+ // mut reader: impl Read,
26+ // mut writer: impl Write,
27+ // log_prefix: Option<&str>,
28+ // ) -> Result<()> {
29+ // let prefix = log_prefix.unwrap_or("");
30+ // let mut buffer = [0; 1024];
31+ // loop {
32+ // let bytes_read = reader.read(&mut buffer)?;
33+ // if bytes_read == 0 {
34+ // break;
35+ // }
36+ // suspend_progress_bar(|| {
37+ // writer.write_all(&buffer[..bytes_read]).unwrap();
38+ // trace!(
39+ // target: EXECUTOR_TARGET,
40+ // "{}{}",
41+ // prefix,
42+ // String::from_utf8_lossy(&buffer[..bytes_read])
43+ // );
44+ // });
45+ // }
46+ // Ok(())
47+ // }
5248
5349 let mut process = cmd
5450 . stdout ( std:: process:: Stdio :: piped ( ) )
5551 . stderr ( std:: process:: Stdio :: piped ( ) )
5652 . spawn ( )
5753 . context ( "failed to spawn the process" ) ?;
58- let stdout = process. stdout . take ( ) . expect ( "unable to get stdout" ) ;
59- let stderr = process. stderr . take ( ) . expect ( "unable to get stderr" ) ;
60- thread:: spawn ( move || {
61- log_tee ( stdout, std:: io:: stdout ( ) , None ) . unwrap ( ) ;
62- } ) ;
54+ // let stdout = process.stdout.take().expect("unable to get stdout");
55+ // let stderr = process.stderr.take().expect("unable to get stderr");
56+ // thread::spawn(move || {
57+ // log_tee(stdout, std::io::stdout(), None).unwrap();
58+ // });
6359
64- thread:: spawn ( move || {
65- log_tee ( stderr, std:: io:: stderr ( ) , Some ( "[stderr]" ) ) . unwrap ( ) ;
66- } ) ;
60+ // thread::spawn(move || {
61+ // log_tee(stderr, std::io::stderr(), Some("[stderr]")).unwrap();
62+ // });
6763
68- cb ( process. id ( ) ) . await ?;
64+ let ( _, exit_status) = tokio:: join!(
65+ cb( process. id( ) . unwrap( ) ) ,
66+ process. wait( )
67+ ) ;
6968
70- process . wait ( ) . context ( "failed to wait for the process" )
69+ exit_status . context ( "failed to wait for the process" )
7170}
7271
7372pub async fn run_command_with_log_pipe ( cmd : Command ) -> Result < ExitStatus > {
0 commit comments