@@ -92,10 +92,15 @@ impl Command {
9292
9393 pub fn output ( & mut self ) -> io:: Result < ( ExitStatus , Vec < u8 > , Vec < u8 > ) > {
9494 let mut cmd = uefi_command_internal:: Command :: load_image ( & self . prog ) ?;
95+
9596 cmd. stdout_init ( ) ?;
97+ cmd. stderr_init ( ) ?;
98+
9699 let stat = cmd. start_image ( ) ?;
97100 let stdout = cmd. stdout ( ) ?;
98- Ok ( ( ExitStatus ( stat) , stdout, Vec :: new ( ) ) )
101+ let stderr = cmd. stderr ( ) ?;
102+
103+ Ok ( ( ExitStatus ( stat) , stdout, stderr) )
99104 }
100105}
101106
@@ -263,6 +268,7 @@ mod uefi_command_internal {
263268 pub struct Command {
264269 handle : NonNull < crate :: ffi:: c_void > ,
265270 stdout : Option < helpers:: Protocol < PipeProtocol > > ,
271+ stderr : Option < helpers:: Protocol < PipeProtocol > > ,
266272 st : Box < r_efi:: efi:: SystemTable > ,
267273 }
268274
@@ -271,7 +277,7 @@ mod uefi_command_internal {
271277 handle : NonNull < crate :: ffi:: c_void > ,
272278 st : Box < r_efi:: efi:: SystemTable > ,
273279 ) -> Self {
274- Self { handle, stdout : None , st }
280+ Self { handle, stdout : None , stderr : None , st }
275281 }
276282
277283 pub fn load_image ( p : & OsStr ) -> io:: Result < Self > {
@@ -349,6 +355,19 @@ mod uefi_command_internal {
349355 Ok ( ( ) )
350356 }
351357
358+ pub fn stderr_init ( & mut self ) -> io:: Result < ( ) > {
359+ let mut protocol =
360+ helpers:: Protocol :: create ( PipeProtocol :: new ( ) , simple_text_output:: PROTOCOL_GUID ) ?;
361+
362+ self . st . standard_error_handle = protocol. handle ( ) . as_ptr ( ) ;
363+ self . st . std_err =
364+ protocol. as_mut ( ) as * mut PipeProtocol as * mut simple_text_output:: Protocol ;
365+
366+ self . stderr = Some ( protocol) ;
367+
368+ Ok ( ( ) )
369+ }
370+
352371 pub fn stdout ( & self ) -> io:: Result < Vec < u8 > > {
353372 if let Some ( stdout) = & self . stdout {
354373 stdout
@@ -361,6 +380,19 @@ mod uefi_command_internal {
361380 Err ( const_io_error ! ( io:: ErrorKind :: NotFound , "stdout not found" ) )
362381 }
363382 }
383+
384+ pub fn stderr ( & self ) -> io:: Result < Vec < u8 > > {
385+ if let Some ( stderr) = & self . stderr {
386+ stderr
387+ . as_ref ( )
388+ . utf8 ( )
389+ . into_string ( )
390+ . map_err ( |_| const_io_error ! ( io:: ErrorKind :: Other , "utf8 conversion failed" ) )
391+ . map ( Into :: into)
392+ } else {
393+ Err ( const_io_error ! ( io:: ErrorKind :: NotFound , "stdout not found" ) )
394+ }
395+ }
364396 }
365397
366398 impl Drop for Command {
0 commit comments