Skip to content

Extends rustdoc on how to caputure output #32338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2016
Merged

Extends rustdoc on how to caputure output #32338

merged 6 commits into from
Apr 15, 2016

Conversation

lukaspustina
Copy link
Contributor

  • The documentation is quite about how to caputure a process' output when using
    std::process::Child::wait_with_output().
  • This PR adds an example for this particular use case.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

/// .stdout(Stdio::piped())
/// .arg("file.txt")
/// .spawn()
/// .unwrap_or_else(|e| { panic!("failed to execute child: {}", e) });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These calls can nowadays be .expect("failed to execute child") I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using the example of output as a template and it does use unwrap_or_else which I prefer since it transports the underlying error. But sure, I'll update the PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's a good point, if you wanna update the other blocks feel free :)

- After discussing with @alexcrichton, the initial commit has been fine.

This reverts commit 3b5cfa3.
@alexcrichton
Copy link
Member

@lukaspustina sorry but do you want to apply the changes here? Or another PR? I'm confused...

@lukaspustina
Copy link
Contributor Author

@alexcrichton I leave the PR as initially intended following the already existing test for output() so that the tests are consistent. Once accepted, I'll adapt both tests to use no_run as you suggested. I'd prefer to keep unwrap_or_else() though, because it transports the underlying error in contrast to expected().

/// By default, stdin, stdout and stderr are inherited from the parent.
/// In order to capture the output into this `Result<Output>` it is
/// necessary to create new pipes between parent and child. Use
/// `stdout(Stdio::piped())` or `stdout(Stdio::piped())`, respectively.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is one of these supposed to be stderr(Stdio::piped())?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh. Of course. Thanks for the catch.

@alexcrichton
Copy link
Member

It may actually be easier to just go ahead and throw the changes into this PR, the cycle time for landing PRs is unfortunately kinda high so may as well land it all at once if we can! (plus there shouldn't be many conflicts).

Also note that expect on Result prints out the error payload so you don't have to worry about losing information in that regard.

- All Rust Doc tests execute the same command `/bin/cat file.txt` which
  `should_panic` on all platforms consistently, because either
  `/bin/cat` or `file.txt` do not exist.
@lukaspustina
Copy link
Contributor Author

@alexcrichton: Done.

@steveklabnik
Copy link
Member

Looks like a legit test failure.

Since I changed no_run to should_panic on some tests, the were run but
two lacked an actual assertion. Further, I missed to check the return
type on another test.
@lukaspustina
Copy link
Contributor Author

@alexcrichton: Ping. Anything I can do to enhance the PR?

@alexcrichton
Copy link
Member

Oh oops, sorry about that! Feel free to ping a PR whenever you update it, unfortunately github doesn't send out notifications for that :(

Other looks good to me, thanks!

@bors: r+ 5613372

@bors
Copy link
Collaborator

bors commented Apr 15, 2016

⌛ Testing commit 5613372 with merge 9debf51...

bors added a commit that referenced this pull request Apr 15, 2016
Extends rustdoc on how to caputure output

- The documentation is quite about how to caputure a process' output when using
  ` std::process::Child::wait_with_output()`.
- This PR adds an example for this particular use case.
@bors bors merged commit 5613372 into rust-lang:master Apr 15, 2016
@lukaspustina lukaspustina deleted the doc-std-process branch April 17, 2016 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants