-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: os/exec: allow setting Context in Cmd #46699
Comments
Mark as proposal since this is requesting an API change. |
What would it mean if exec.Cmd.Context was mutated after initialization? Perhaps we should be inspired by net/http.Request.Context and WithContext? |
We still need to do #43724, which included replacing the unexported lookPathErr with an exported Err. If we do that, then this use case can be satisfied by just calling CommandContext and then editing Err away. It sounds like maybe we should do that? |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
os/exec allows spawning and settings most options of
exec.Cmd
without usingexec.Command()
, however thectx
value can only be set when invoking usingexec.CommandContext()
.Because I instantiate it with a number of custom settings I typically not use
exec.Command()
but still need to use the context.Hence, I am requesting if
ctx
can be instead renamedContext
so it can be set cleanly. This change can be made so it doesn't affect any existing code, and is much cleaner.What did you expect to see?
An easy way to set Cmd.ctx:
What did you see instead?
This is ugly but needed because
exec.Command
will try to useLookPath
and setlookPathErr
if it fails. In this specific case I do not use lookpath because argv[0] is special and requires SysProcAttr to appear valid, so instead I give it another binary that I know will exist.LookPath
will return an error even when given a full path if it doesn't appear executable.The text was updated successfully, but these errors were encountered: