-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
subprocess.run throws exception when input and stdin are passed as kwargs #79067
Comments
If input and stdin parameters are passed as keyword arguments to subprocess.run, an exception is thrown even if input and stdin are both None. The exception is ValueError: stdin and input arguments may not both be used. I attach a minimal working example of the bug |
What is wrong with this? |
subprocess.run('ls', input=b'', stdin=None) # this is ok
kwargs = {'input': b'', 'stdin': None}
subprocess.run('ls', **kwargs) # this throws exception The two calls should have the same behaviour, but one throws exception and the other doesn't. I think the exception shouldn't be thrown, because stdin is None. |
I just tried: subprocess.run('ls', input=b'', stdin=None) and I got the same ValueError as for passing using kwargs. Where did you get the idea subprocess.run('ls', input=b'', stdin=None) worked? |
The actual code receives input by name, but stdin is received in **kwargs. The test is just: if input is not None:
if 'stdin' in kwargs:
raise ValueError(...)
kwargs['stdin'] = PIPE Perhaps just change `if 'stdin' in kwargs:` to: if kwargs.get('stdin') is not None: so it obeys the documented API (that says stdin defaults to None, and therefore passing stdin=None explicitly should be equivalent to not passing it at all)? |
Sorry, the example was wrong. Both calls have the same behaviour.
The actual problem is this. The fix you propose works for me. |
I opened a PR with @josh.r proposed change. |
thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: