@@ -20,6 +20,7 @@ use ffi::OsStr;
20
20
use fmt;
21
21
use io:: { self , Error , ErrorKind } ;
22
22
use path;
23
+ use str;
23
24
use sys:: pipe:: { self , AnonPipe } ;
24
25
use sys:: process as imp;
25
26
use sys_common:: { AsInner , AsInnerMut , FromInner , IntoInner } ;
@@ -400,6 +401,32 @@ pub struct Output {
400
401
pub stderr : Vec < u8 > ,
401
402
}
402
403
404
+ // If either stderr or stdout are valid utf8 strings it prints the valid
405
+ // strings, otherwise it prints the byte sequence instead
406
+ #[ stable( feature = "process_output_debug" , since = "1.7.0" ) ]
407
+ impl fmt:: Debug for Output {
408
+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
409
+
410
+ let stdout_utf8 = str:: from_utf8 ( & self . stdout ) ;
411
+ let stdout_debug: & fmt:: Debug = match stdout_utf8 {
412
+ Ok ( ref str) => str,
413
+ Err ( _) => & self . stdout
414
+ } ;
415
+
416
+ let stderr_utf8 = str:: from_utf8 ( & self . stderr ) ;
417
+ let stderr_debug: & fmt:: Debug = match stderr_utf8 {
418
+ Ok ( ref str) => str,
419
+ Err ( _) => & self . stderr
420
+ } ;
421
+
422
+ fmt. debug_struct ( "Output" )
423
+ . field ( "status" , & self . status )
424
+ . field ( "stdout" , stdout_debug)
425
+ . field ( "stderr" , stderr_debug)
426
+ . finish ( )
427
+ }
428
+ }
429
+
403
430
/// Describes what to do with a standard I/O stream for a child process.
404
431
#[ stable( feature = "process" , since = "1.0.0" ) ]
405
432
pub struct Stdio ( StdioImp ) ;
0 commit comments