about summary refs log tree commit diff
path: root/src/libstd/process.rs
AgeCommit message (Collapse)AuthorLines
2017-02-05Rollup merge of #38518 - nagisa:exec-doc, r=alexcrichtonCorey Farwell-2/+19
Expand documentation of process::exit and exec Show a conventional way to use process::exit when destructors are considered important and also mention that the same caveats wrt destructors apply to exec as well.
2017-01-29Fix a few impl stability attributesOliver Middleton-5/+5
The versions show up in rustdoc.
2017-01-25Auto merge of #38856 - zackw:process-envs, r=aturonbors-1/+36
Add std::process::Command::envs() `Command::envs()` adds a vector of key-value pairs to the child process environment all at once. Suggested in #38526. This is not fully baked and frankly I'm not sure it even _works_, but I need some help finishing it up, and this is the simplest way to show you what I've got. The problems I know exist and don't know how to solve, from most to least important, are: * [ ] I don't know if the type signature of the new function is correct. * [x] The new test might not be getting run. I didn't see it go by in the output of `x.py test src/libstd --stage 1`. * [x] The tidy check says ``process.rs:402: different `since` than before`` which I don't know what it means. r? @brson
2017-01-21Generalize envs() and args() to iterators.Zack Weinberg-6/+9
* Command::envs() now takes anything that is IntoIterator<Item=(K, V)> where both K and V are AsRef<OsStr>. * Since we're not 100% sure that's the right signature, envs() is now marked unstable. (You can use envs() with HashMap<str, str> but not Vec<(str, str)>, for instance.) * Update the test to match. * By analogy, args() now takes any IntoIterator<Item=S>, S: AsRef<OsStr>. This should be uncontroversial.
2017-01-19Expand documentation of process::exit and execSimonas Kazlauskas-2/+19
Show a conventional way to use process::exit when destructors are considered important and also mention that the same caveats wrt destructors apply to exec as well.
2017-01-10Fixes:Zack Weinberg-1/+1
* give the new feature its own feature tag * correct a lifetime problem in the test * use .output() instead of .spawn() in the test so that output is actually collected * correct the same error in the test whose skeleton I cribbed
2017-01-09Auto merge of #38866 - alexcrichton:try-wait, r=aturonbors-0/+42
std: Add a nonblocking `Child::try_wait` method This commit adds a new method to the `Child` type in the `std::process` module called `try_wait`. This method is the same as `wait` except that it will not block the calling thread and instead only attempt to collect the exit status. On Unix this means that we call `waitpid` with the `WNOHANG` flag and on Windows it just means that we pass a 0 timeout to `WaitForSingleObject`. Currently it's possible to build this method out of tree, but it's unfortunately tricky to do so. Specifically on Unix you essentially lose ownership of the pid for the process once a call to `waitpid` has succeeded. Although `Child` tracks this state internally to be resilient to multiple calls to `wait` or a `kill` after a successful wait, if the child is waited on externally then the state inside of `Child` is not updated. This means that external implementations of this method must be extra careful to essentially not use a `Child`'s methods after a call to `waitpid` has succeeded (even in a nonblocking fashion). By adding this functionality to the standard library it should help canonicalize these external implementations and ensure they can continue to robustly reuse the `Child` type from the standard library without worrying about pid ownership.
2017-01-06std: Add a nonblocking `Child::try_wait` methodAlex Crichton-0/+42
This commit adds a new method to the `Child` type in the `std::process` module called `try_wait`. This method is the same as `wait` except that it will not block the calling thread and instead only attempt to collect the exit status. On Unix this means that we call `waitpid` with the `WNOHANG` flag and on Windows it just means that we pass a 0 timeout to `WaitForSingleObject`. Currently it's possible to build this method out of tree, but it's unfortunately tricky to do so. Specifically on Unix you essentially lose ownership of the pid for the process once a call to `waitpid` has succeeded. Although `Child` tracks this state internally to be resilient to multiple calls to `wait` or a `kill` after a successful wait, if the child is waited on externally then the state inside of `Child` is not updated. This means that external implementations of this method must be extra careful to essentially not use a `Child`'s methods after a call to `waitpid` has succeeded (even in a nonblocking fashion). By adding this functionality to the standard library it should help canonicalize these external implementations and ensure they can continue to robustly reuse the `Child` type from the standard library without worrying about pid ownership.
2017-01-05Add std::process::Command::envs()Zack Weinberg-0/+32
Command::envs() adds a vector of key-value pairs to the child process environment all at once. Suggested in #38526.
2017-01-04Fix formattingabhijeetbhagat-1/+1
2017-01-04Fix formattingabhijeetbhagat-10/+10
2017-01-03Fix process module tests to run on Windowsabhijeetbhagat-18/+67
2016-12-20Rollup merge of #38006 - frewsxcv:libstd-debug, r=alexcrichtonAlex Crichton-0/+39
Implement `fmt::Debug` for all structures in libstd. Part of https://github.com/rust-lang/rust/issues/31869. Also turn on the `missing_debug_implementations` lint at the crate level.
2016-12-18Implement `fmt::Debug` for all structures in libstd.Corey Farwell-0/+39
Part of https://github.com/rust-lang/rust/issues/31869. Also turn on the `missing_debug_implementations` lint at the crate level.
2016-12-18Document platform-specific differences for `std::process::exit`.Corey Farwell-0/+17
Fixes https://github.com/rust-lang/rust/issues/35046.
2016-12-07Rollup merge of #38151 - GuillaumeGomez:exit-examples, r=frewsxcvGuillaume Gomez-0/+8
Add examples for exit function r? @frewsxcv
2016-12-05Auto merge of #38098 - luser:windows-commandext, r=alexcrichtonbors-0/+58
Add std::os::windows::process::CommandExt. Fixes #37827 This adds a CommandExt trait for Windows along with an implementation of it for std::process::Command with methods to set the process creation flags that are passed to CreateProcess.
2016-12-03Add examples for exit functionGuillaume Gomez-0/+8
2016-12-01Auto merge of #38018 - sourcefrog:doc, r=alexcrichtonbors-0/+8
Document that Process::command will search the PATH
2016-11-30just add one method named creation_flags, fix the tidy errorTed Mielczarek-2/+3
2016-11-30Document that Process::command will search the PATHMartin Pool-0/+8
2016-11-30Add std::os::windows::process::CommandExt, with set_creation_flags and ↵Ted Mielczarek-0/+57
add_creation_flags methods. Fixes #37827 This adds a CommandExt trait for Windows along with an implementation of it for std::process::Command with methods to set the process creation flags that are passed to CreateProcess.
2016-11-17Add std::process::abortSteven Fackler-0/+15
This calls libc abort on Unix and fastfail on Windows.
2016-09-30Auto merge of #36339 - brson:emscripten-new, r=alexcrichtonbors-1/+1
Working asmjs and wasm targets This patch set results in a working standard library for the asmjs-unknown-emscripten and wasm32-unknown-emscripten targets. It is based on the work of @badboy and @rschulman. It does a few things: - Updates LLVM with the emscripten [fastcomp](https://github.com/rust-lang/llvm/pull/50) patches, which include the pnacl IR legalizer and the asm.js backend. This patch is thought not to have any significant effect on existing targets. - Teaches rustbuild to correctly link C code with emscripten - Updates gcc-rs to work correctly with emscripten - Teaches rustbuild to run crate tests for emscripten with node - Modifies Thread::new to return an error on emscripten, to facilitate debugging a common failure mode - Modifies libtest to run in single-threaded mode for emscripten - Ignores a host of tests that don't work yet, mostly dealing with threads and I/O - Updates libc with wasm32 definitions (presently the same as asmjs) - Adds a wasm32-unknown-emscripten target that feeds the output of LLVM's asmjs backend through emcc to generate wasm Notes and caveats: - This is only known to work with `--enable-rustbuild`. - The wasm32 target can't be tested correctly yet because of issues in compiletest and limitations in node https://github.com/kripken/emscripten/issues/4542, but hello.rs does seem to work when run on node via the binaryen interpreter - This requires an up to date installation of the emscripten sdk from its incoming branch - Unwinding is very broken - When enabling the emscripten targets jemalloc is disabled for all targets, which results in test failures for the host Next steps are to fix the jemalloc issue, start building the two emscripten targets on the auto builders, then start producing nightlies. https://github.com/rust-lang/rust/issues/36317 tracks work on this. Fixes https://github.com/rust-lang/rust/issues/36515 Fixes https://github.com/rust-lang/rust/issues/36515 Fixes https://github.com/rust-lang/rust/issues/36356
2016-09-30Ignore entire test modules on emscripten instead of individual testsBrian Anderson-18/+1
2016-09-30Ignore lots and lots of std tests on emscriptenBrian Anderson-0/+17
2016-09-30Improve process module doc a bitGuillaume Gomez-1/+19
2016-08-24Use `#[prelude_import]` in `libstd`.Jeffrey Seyfried-2/+0
2016-07-12Add doc example for `std::process::ExitStatus::success`.Corey Farwell-0/+17
2016-07-11`std::process` doc improvements.Corey Farwell-11/+29
* Link to `process::Command` from `process::Child`. * Move out inline Markdown link in doc comment. * Link to `process::Child::wait` from `process::Child`. * Link to `process::Child` from `process::ChildStdin`. * Link to `process::Child` from `process::ChildStdout`. * Link to `process::Child` from `process::ChildStderr`.
2016-06-16doc: fix mis-named binding & remove not needed `mut`Tshepang Lekhonkhobe-8/+9
2016-06-09doc: intro should be 1 sentenceTshepang Lekhonkhobe-2/+4
Also, do not repeat name of type
2016-06-02doc: typoTshepang Lekhonkhobe-1/+1
2016-05-09Auto merge of #33224 - alexcrichton:create-exit-status, r=aturonbors-0/+6
std: Allow creating ExitStatus from raw values Sometimes a process may be waited on externally from the standard library, in which case it can be useful to create a raw `ExitStatus` structure to return. This commit extends the existing Unix `ExitStatusExt` extension trait and adds a new Windows-specific `ExitStatusExt` extension trait to do this. The methods are currently called `ExitStatus::from_raw`. cc #32713
2016-05-01Add process types documentationGuillaume Gomez-4/+196
2016-04-26std: Allow creating ExitStatus from raw valuesAlex Crichton-0/+6
Sometimes a process may be waited on externally from the standard library, in which case it can be useful to create a raw `ExitStatus` structure to return. This commit extends the existing Unix `ExitStatusExt` extension trait and adds a new Windows-specific `ExitStatusExt` extension trait to do this. The methods are currently called `ExitStatus::from_raw`. cc #32713
2016-04-15Auto merge of #32338 - lukaspustina:doc-std-process, r=alexcrichtonbors-11/+37
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.
2016-03-26Rollup merge of #32257 - alexcrichton:fix-status-stdin, r=aturonManish Goregaokar-1/+1
std: Fix inheriting stdin on status() This regression was accidentally introduced in #31618, and it's just flipping a boolean! Closes #32254
2016-03-22try! -> ?Jorge Aparicio-1/+1
Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry
2016-03-22Fixes test which are now run due to should_panicLukas Pustina-1/+5
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.
2016-03-21Adjusts all rust doc test to use `expect` and `should_panic`Lukas Pustina-14/+13
- 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.
2016-03-19Fixes 2. stdout to stderr in rustdocLukas Pustina-1/+1
2016-03-19Revert "Tags new test as `no_run` and uses expect()"Lukas Pustina-3/+4
- After discussing with @alexcrichton, the initial commit has been fine. This reverts commit 3b5cfa3ecf4e44b251ce121ab5dcf53c35de8eea.
2016-03-18Tags new test as `no_run` and uses expect()Lukas Pustina-4/+3
2016-03-18Extends rustdoc on how to caputure outputLukas Pustina-0/+23
2016-03-14std: Fix inheriting stdin on status()Alex Crichton-1/+1
This regression was accidentally introduced in #31618, and it's just flipping a boolean! Closes #32254
2016-03-09std: Don't spawn threads in `wait_with_output`Alex Crichton-16/+20
Semantically there's actually no reason for us to spawn threads as part of the call to `wait_with_output`, and that's generally an incredibly heavyweight operation for just reading a few bytes (especially when stderr probably rarely has bytes!). An equivalent operation in terms of what's implemented today would be to just drain both pipes of all contents and then call `wait` on the child process itself. On Unix we can implement this through some convenient use of the `select` function, whereas on Windows we can make use of overlapped I/O. Note that on Windows this requires us to use named pipes instead of anonymous pipes, but they're semantically the same under the hood.
2016-03-08std: Don't always create stdin for childrenAlex Crichton-3/+4
For example if `Command::output` or `Command::status` is used then stdin is just immediately closed. Add an option for this so as an optimization we can avoid creating pipes entirely. This should help reduce the number of active file descriptors when spawning processes on Unix and the number of active handles on Windows.
2016-03-08std: Funnel read_to_end through to one locationAlex Crichton-0/+6
This pushes the implementation detail of proxying `read_to_end` through to `read_to_end_uninitialized` all the way down to the `FileDesc` and `Handle` implementations on Unix/Windows. This way intermediate layers will also be able to take advantage of this optimized implementation. This commit also adds the optimized implementation for `ChildStdout` and `ChildStderr`.
2016-02-10std: Push process stdio setup in std::sysAlex Crichton-85/+44
Most of this is platform-specific anyway, and we generally have to jump through fewer hoops to do the equivalent operation on Windows. One benefit for Windows today is that this new structure avoids an extra `DuplicateHandle` when creating pipes. For Unix, however, the behavior should be the same. Note that this is just a pure refactoring, no functionality was added or removed.