@@ -68,23 +68,49 @@ pub fn run_shell_command_with_log(
6868 log : & Logger ,
6969 os : & str ,
7070 command : Command ,
71+ ) -> Result < String , Error > {
72+ run_shell_command_with_stderr ( log, os, command, false )
73+ }
74+
75+ pub fn run_shell_command_with_stderr (
76+ log : & Logger ,
77+ os : & str ,
78+ command : Command ,
79+ stderr : bool ,
7180) -> Result < String , Error > {
7281 log. debug ( format ! ( "Running command: {}" , command. display( ) ) ) ;
73- let output = run_shell_command_by_os ( os, command) ?;
82+ let output = run_shell_command_by_os_stderr ( os, command, stderr ) ?;
7483 log. debug ( format ! ( "Output: {:?}" , output) ) ;
7584 Ok ( output)
7685}
7786
7887pub fn run_shell_command_by_os ( os : & str , command : Command ) -> Result < String , Error > {
88+ run_shell_command_by_os_stderr ( os, command, false )
89+ }
90+
91+ pub fn run_shell_command_by_os_stderr (
92+ os : & str ,
93+ command : Command ,
94+ stderr : bool ,
95+ ) -> Result < String , Error > {
7996 let ( shell, flag) = if WINDOWS . is ( os) {
8097 ( "cmd" , "/c" )
8198 } else {
8299 ( "sh" , "-c" )
83100 } ;
84- run_shell_command ( shell, flag, command)
101+ run_shell_command_stderr ( shell, flag, command, stderr )
85102}
86103
87104pub fn run_shell_command ( shell : & str , flag : & str , command : Command ) -> Result < String , Error > {
105+ run_shell_command_stderr ( shell, flag, command, false )
106+ }
107+
108+ pub fn run_shell_command_stderr (
109+ shell : & str ,
110+ flag : & str ,
111+ command : Command ,
112+ stderr : bool ,
113+ ) -> Result < String , Error > {
88114 let mut process = std:: process:: Command :: new ( shell) ;
89115 process. arg ( flag) ;
90116
@@ -96,9 +122,11 @@ pub fn run_shell_command(shell: &str, flag: &str, command: Command) -> Result<St
96122 }
97123 }
98124 let output = process. output ( ) ?;
99- let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
100- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
101- Ok ( strip_trailing_newline ( & ( stdout + " " + stderr) ) . to_string ( ) )
125+ let mut stdout = String :: from_utf8_lossy ( & output. stdout ) ;
126+ if stderr {
127+ stdout = stdout + " " + String :: from_utf8_lossy ( & output. stderr ) ;
128+ }
129+ Ok ( strip_trailing_newline ( & stdout) . to_string ( ) )
102130}
103131
104132pub fn strip_trailing_newline ( input : & str ) -> & str {
0 commit comments