Description
This is now implemented on nightly via #77029.
Summary
The following accessors are available on Command
behind the #![feature(command_access)]
gate:
Unresolved issues
Some concerns I had with the implementation, but probably not important:
- Values with NULs on Unix will be returned as
"<string-with-nul>"
. I don't think it is practical to avoid this, since otherwise a whole separate copy of all the values would need to be kept inCommand
. - Does not handle
arg0
on Unix. This can be awkward to support inget_args
and is rarely used. I figure if someone really wants it, it can be added toCommandExt
as a separate method. - Does not offer a way to detect
env_clear
. I'm uncertain if it would be useful for anyone. - Does not offer a way to get an environment variable by name (
get_env
). I figure this can be added later if anyone really wants it. I think the motivation for this is weak, though. Also, the API could be a little awkward (return aOption<Option<&OsStr>>
?). -
get_envs
could skip "cleared" entries and just return&OsStr
values instead ofOption<&OsStr>
. I'm on the fence here. My use case is to display a shell command, and I only intend it to be roughly equivalent to the actual execution, and I probably won't displayNone
entries. I erred on the side of providing extra information, but I suspect many situations will just filter out theNone
s. - Could implement more iterator stuff (like
DoubleEndedIterator
).
Original issue below
The the std::process::Command
builder is useful for building up a Command in a cross-platform way. I've found that it would be useful to extract the name, args, environment, etc. of a Command
they have been set.
There are at least two places in the Rust compiler that would benefit from such an API. Instead, the authors have had to resort to wrappers instead of using Command
directly.
https://github.com/rust-lang/rust/blob/master/src/tools/compiletest/src/runtest.rs#L1527
https://github.com/rust-lang/rust/blob/master/src/librustc_trans/back/command.rs