Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

swlynch99
Copy link

@swlynch99 swlynch99 commented Mar 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant