matklad / xshell

Apache License 2.0
695 stars 28 forks source link

Add `Cmd::before_spawn` to allow modifying the resulting `std::process::Command` before spawning it #81

Open swlynch99 opened 8 months ago

swlynch99 commented 8 months ago

Hey! I've been using this crate a bunch and it's been great!

For one of my use cases I need to run a process under a different uid. If I want to do this I can use xshell to build the command then I need to eject out and convert it directly to std::process::Command to set the uid. If I do that, though, I can no longer use read and I end up needing to write a bunch of code to replicate it.

Adding a uid method felt too platform-specific so this PR instead adds a before_spawn method that registers a function that gets called with the std::process::Command just before it is spawned. It is based on the before_spawn method in duct which does the exact same thing.

Notes