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
CmdData needs to be Clone + Send + Sync and Box<dyn Fn(&mut Command)> is none of those so I ended having to place the list of methods directly in Cmd.
I started off trying to bound the functions by 'a but that broke one of the tests so I've left the hook as Box<dyn Fn(&mut Command) + 'static> instead.
Hook functions don't get run when converting Cmd to std::process::Command since they are fallible. I have documented this in the method documentation.
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 useread
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 abefore_spawn
method that registers a function that gets called with thestd::process::Command
just before it is spawned. It is based on thebefore_spawn
method in duct which does the exact same thing.Notes
CmdData
needs to beClone + Send + Sync
andBox<dyn Fn(&mut Command)>
is none of those so I ended having to place the list of methods directly inCmd
.'a
but that broke one of the tests so I've left the hook asBox<dyn Fn(&mut Command) + 'static>
instead.Cmd
tostd::process::Command
since they are fallible. I have documented this in the method documentation.