@@ -23,8 +23,8 @@ use super::helpers;
2323
2424pub struct Command {
2525 prog : OsString ,
26- stdout : Option < uefi_command_internal :: PipeProtocol > ,
27- stderr : Option < uefi_command_internal :: PipeProtocol > ,
26+ stdout : Option < Stdio > ,
27+ stderr : Option < Stdio > ,
2828}
2929
3030// passed back to std::process with the pipes connected to the child, if any
@@ -65,19 +65,11 @@ impl Command {
6565 }
6666
6767 pub fn stdout ( & mut self , stdout : Stdio ) {
68- self . stdout = match stdout {
69- Stdio :: MakePipe => Some ( uefi_command_internal:: PipeProtocol :: new ( ) ) ,
70- Stdio :: Null => Some ( uefi_command_internal:: PipeProtocol :: null ( ) ) ,
71- _ => None ,
72- } ;
68+ self . stdout = Some ( stdout) ;
7369 }
7470
7571 pub fn stderr ( & mut self , stderr : Stdio ) {
76- self . stderr = match stderr {
77- Stdio :: MakePipe => Some ( uefi_command_internal:: PipeProtocol :: new ( ) ) ,
78- Stdio :: Null => Some ( uefi_command_internal:: PipeProtocol :: null ( ) ) ,
79- _ => None ,
80- } ;
72+ self . stderr = Some ( stderr) ;
8173 }
8274
8375 pub fn get_program ( & self ) -> & OsStr {
@@ -104,31 +96,56 @@ impl Command {
10496 unsupported ( )
10597 }
10698
99+ fn create_pipe (
100+ s : Stdio ,
101+ ) -> io:: Result < Option < helpers:: Protocol < uefi_command_internal:: PipeProtocol > > > {
102+ match s {
103+ Stdio :: MakePipe => helpers:: Protocol :: create (
104+ uefi_command_internal:: PipeProtocol :: new ( ) ,
105+ simple_text_output:: PROTOCOL_GUID ,
106+ )
107+ . map ( Some ) ,
108+ Stdio :: Null => helpers:: Protocol :: create (
109+ uefi_command_internal:: PipeProtocol :: null ( ) ,
110+ simple_text_output:: PROTOCOL_GUID ,
111+ )
112+ . map ( Some ) ,
113+ Stdio :: Inherit => Ok ( None ) ,
114+ }
115+ }
116+
107117 pub fn output ( & mut self ) -> io:: Result < ( ExitStatus , Vec < u8 > , Vec < u8 > ) > {
108118 let mut cmd = uefi_command_internal:: Command :: load_image ( & self . prog ) ?;
109119
110- let stdout: helpers:: Protocol < uefi_command_internal:: PipeProtocol > =
120+ let stdout: Option < helpers:: Protocol < uefi_command_internal:: PipeProtocol > > =
111121 match self . stdout . take ( ) {
112- Some ( s) => helpers :: Protocol :: create ( s , simple_text_output :: PROTOCOL_GUID ) ,
122+ Some ( s) => Self :: create_pipe ( s ) ,
113123 None => helpers:: Protocol :: create (
114124 uefi_command_internal:: PipeProtocol :: new ( ) ,
115125 simple_text_output:: PROTOCOL_GUID ,
116- ) ,
126+ )
127+ . map ( Some ) ,
117128 } ?;
118129
119- let stderr: helpers:: Protocol < uefi_command_internal:: PipeProtocol > =
130+ let stderr: Option < helpers:: Protocol < uefi_command_internal:: PipeProtocol > > =
120131 match self . stderr . take ( ) {
121- Some ( s) => helpers :: Protocol :: create ( s , simple_text_output :: PROTOCOL_GUID ) ,
132+ Some ( s) => Self :: create_pipe ( s ) ,
122133 None => helpers:: Protocol :: create (
123134 uefi_command_internal:: PipeProtocol :: new ( ) ,
124135 simple_text_output:: PROTOCOL_GUID ,
125- ) ,
136+ )
137+ . map ( Some ) ,
126138 } ?;
127139
128- cmd. stdout_init ( stdout) ?;
129- cmd. stderr_init ( stderr) ?;
140+ if let Some ( stdout) = stdout {
141+ cmd. stdout_init ( stdout) ?;
142+ }
143+ if let Some ( stderr) = stderr {
144+ cmd. stderr_init ( stderr) ?;
145+ }
130146
131147 let stat = cmd. start_image ( ) ?;
148+
132149 let stdout = cmd. stdout ( ) ?;
133150 let stderr = cmd. stderr ( ) ?;
134151
0 commit comments