-
Notifications
You must be signed in to change notification settings - Fork 303
Run an external command and collect stdout #108
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
Comments
|
By non-contrived I mean things that you couldn't just do in ordinary Rust. So I would prefer not to show
|
oh now I get it. How about these then:
something simple yet not easily doable with std |
Do we want to make sure the command used is commonly available on both Windows and unix systems? If so that probably limits this to commands like |
Yes good call, that would be ideal. |
Would it be acceptable to pull in the |
Yes that would be fine! What do you have in mind? |
Off the top of my head, parsing something like
I'm happy to make a PR for this one when I get home. |
Okay that seems reasonable to me. If someone wanted to get commit hashes and messages would you feel comfortable recommending this shell command + regex approach over using the |
For something reasonably simple like this I'd recommend parsing the process's output like we're doing here. Anything more complex though and it's probably going to be easier to use the library. As it is, this should just be a couple lines of |
Makes sense! I look forward to the PR. |
I've made an initial implementation (gist). @dtolnay, any chance you can give it a look over and see if it can be improved? In particular, the error handling on line 32 (where I'm creating a new |
@Michael-F-Bryan This looks great!. fn run() -> Result<()> {
//actual main
Ok(())
}
quick_main!(run); The rationale is neatly explained in https://github.com/brson/rust-cookbook/pull/53#issuecomment-300244571 |
Cheers for the links, I've updated the gist and added Do you think that intermediate Also, which section would this belong in? I was thinking of adding it to the bottom of the "basics" section, but if we end up adding examples like piping one subprocess's output into another or running a child process in the background and doing other things while you wait for it to exit, it may be worth creating a new section in the cookbook. Thoughts? |
The gist looks excellent, please create a PR. I would add the example to the "basics" section for now. Once we have more examples we will think about how these should be split. |
Does anyone have non-contrived examples? Some ideas:
nm
to list symbols in the current executablegit rev-parse --verify HEAD
The text was updated successfully, but these errors were encountered: