1- use std:: io:: { Write , Error } ;
1+ use std:: io:: { Write , Error , ErrorKind } ;
22use std:: process:: { Command , Stdio } ;
33use std:: result:: Result ;
44use types:: ExecutorResult ;
@@ -13,15 +13,15 @@ pub fn run_stdin(work_dir: &str, stdin: &str, args: &[&str]) -> Result<ExecutorR
1313 . stderr ( Stdio :: piped ( ) ) ;
1414
1515 let mut child = command
16- . spawn ( )
17- . expect ( "Failed to spawn child process" ) ;
16+ . spawn ( ) ? ;
17+ // .expect("Failed to spawn child process");
1818
1919 {
20- let stdin_stream = child. stdin . as_mut ( ) . expect ( "Failed to open stdin" ) ;
21- stdin_stream. write_all ( stdin. as_bytes ( ) ) . expect ( "Failed to write to stdin" ) ;
20+ let stdin_stream = child. stdin . as_mut ( ) . ok_or ( Error :: new ( ErrorKind :: Other , "Failed to open stdin" ) ) ? ; //. expect("Failed to open stdin");
21+ stdin_stream. write_all ( stdin. as_bytes ( ) ) ? ; // .expect("Failed to write to stdin");
2222 }
2323
24- let output = child. wait_with_output ( ) . expect ( "Failed to read stdout" ) ;
24+ let output = child. wait_with_output ( ) ? ; // .expect("Failed to read stdout");
2525
2626 let code = match output. status . code ( ) {
2727 Some ( code) => code,
@@ -40,7 +40,17 @@ pub fn run(work_dir: &str, args: &[&str]) -> Result<ExecutorResult, Error>{
4040}
4141
4242pub fn run_bash_stdin ( work_dir : & str , command : & str , stdin : & str ) -> Result < ExecutorResult , Error > {
43- run_stdin ( work_dir, stdin, & [ "bash" , "-c" , command] )
43+ match run_stdin ( work_dir, stdin, & [ "bash" , "-c" , command] ) {
44+ Ok ( executor_result) => Ok ( executor_result) ,
45+ Err ( e) => {
46+ if let ErrorKind :: NotFound = e. kind ( ) {
47+ println ! ( "aqui" ) ;
48+ run_stdin ( work_dir, stdin, & [ "sh" , "-c" , command] )
49+ } else {
50+ Err ( e)
51+ }
52+ }
53+ }
4454}
4555
4656/* pub fn run_bash(work_dir: &str, command: &str) -> Result<ExecutorResult, Error> {
0 commit comments