Skip to content

Commit

Permalink
auto merge of #15566 : japaric/rust/command-clone, r=alexcrichton
Browse files Browse the repository at this point in the history
Allows use cases like this one:

``` rust
use std::io::Command;

fn main() {
    let mut cmd = Command::new("ls");
    cmd.arg("-l");

    for &dir in ["a", "b", "c"].iter() {
        println!("{}", cmd.clone().arg(dir));
    }
}
```

Output:
```
ls '-l' 'a'
ls '-l' 'b'
ls '-l' 'c'
```
Without the `clone()`, you'll end up with:
```
ls '-l' 'a'
ls '-l' 'a' 'b'
ls '-l' 'a' 'b' 'c'
```

cc #15294
  • Loading branch information
bors committed Jul 10, 2014
2 parents 6372915 + 6d50828 commit f865812
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libstd/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub struct Process {
///
/// let output = process.stdout.get_mut_ref().read_to_end();
/// ```
#[deriving(Clone)]
pub struct Command {
// The internal data for the builder. Documented by the builder
// methods below, and serialized into rt::rtio::ProcessConfig.
Expand Down Expand Up @@ -340,6 +341,7 @@ pub struct ProcessOutput {
}

/// Describes what to do with a standard io stream for a child process.
#[deriving(Clone)]
pub enum StdioContainer {
/// This stream will be ignored. This is the equivalent of attaching the
/// stream to `/dev/null`
Expand Down

0 comments on commit f865812

Please sign in to comment.