@@ -1491,6 +1491,66 @@ impl From<fs::File> for Stdio {
1491
1491
}
1492
1492
}
1493
1493
1494
+ #[ stable( feature = "stdio_from_stdio" , since = "CURRENT_RUSTC_VERSION" ) ]
1495
+ impl From < io:: Stdout > for Stdio {
1496
+ /// Redirect command stdout/stderr to our stdout
1497
+ ///
1498
+ /// # Examples
1499
+ ///
1500
+ /// ```rust
1501
+ /// #![feature(exit_status_error)]
1502
+ /// use std::io;
1503
+ /// use std::process::Command;
1504
+ ///
1505
+ /// # fn test() -> Result<(), Box<dyn std::error::Error>> {
1506
+ /// let output = Command::new("whoami")
1507
+ // "whoami" is a command which exists on both Unix and Windows,
1508
+ // and which succeeds, producing some stdout output but no stderr.
1509
+ /// .stdout(io::stdout())
1510
+ /// .output()?;
1511
+ /// output.status.exit_ok()?;
1512
+ /// assert!(output.stdout.is_empty());
1513
+ /// # Ok(())
1514
+ /// # }
1515
+ /// #
1516
+ /// # if cfg!(unix) {
1517
+ /// # test().unwrap();
1518
+ /// # }
1519
+ /// ```
1520
+ fn from ( inherit : io:: Stdout ) -> Stdio {
1521
+ Stdio :: from_inner ( inherit. into ( ) )
1522
+ }
1523
+ }
1524
+
1525
+ #[ stable( feature = "stdio_from_stdio" , since = "CURRENT_RUSTC_VERSION" ) ]
1526
+ impl From < io:: Stderr > for Stdio {
1527
+ /// Redirect command stdout/stderr to our stderr
1528
+ ///
1529
+ /// # Examples
1530
+ ///
1531
+ /// ```rust
1532
+ /// #![feature(exit_status_error)]
1533
+ /// use std::io;
1534
+ /// use std::process::Command;
1535
+ ///
1536
+ /// # fn test() -> Result<(), Box<dyn std::error::Error>> {
1537
+ /// let output = Command::new("whoami")
1538
+ /// .stdout(io::stderr())
1539
+ /// .output()?;
1540
+ /// output.status.exit_ok()?;
1541
+ /// assert!(output.stdout.is_empty());
1542
+ /// # Ok(())
1543
+ /// # }
1544
+ /// #
1545
+ /// # if cfg!(unix) {
1546
+ /// # test().unwrap();
1547
+ /// # }
1548
+ /// ```
1549
+ fn from ( inherit : io:: Stderr ) -> Stdio {
1550
+ Stdio :: from_inner ( inherit. into ( ) )
1551
+ }
1552
+ }
1553
+
1494
1554
/// Describes the result of a process after it has terminated.
1495
1555
///
1496
1556
/// This `struct` is used to represent the exit status or other termination of a child process.
0 commit comments