You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FileNotFoundException raised by subprocess.call #69076
It would be nice to notify the reader that this function can raise FileNotFoundException. It is raised in case when the binary one wants to call does not exist.
Example:
Python 3.4.0 (default, Jun 19 2015, 14:20:21)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.check_call(["foo", "bar"])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/subprocess.py", line 552, in check_call
retcode = call(*popenargs, **kwargs)
File "/usr/lib/python3.4/subprocess.py", line 533, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.4/subprocess.py", line 848, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.4/subprocess.py", line 1446, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'foo'
We don't in general document all the exceptions that can be raised by a piece of code. This could be an edge case, though. Let's see what others thing.
The FileNotFoundException exception is coming from the Popen call, and the docs for subprocess.check_call already mention that it delegates to Popen.
There are quite a few different exceptions that Popen could raise, so I think David's general comment is valid, it would not make sense to mention just this one, or to try and list all of them.
That said, the current wording does seem to imply that only CalledProcessErrors can be raised by this function so it might be worth clarifying that other exceptions can occur if the command could not run at all (without enumerating the precise exceptions).
New changeset 19a304b by DonnaDia in branch 'main': bpo-24888: Clarify subprocess.check_call propagates exceptions if unable to start process (GH-28018) 19a304b
New changeset 2363910 by Miss Islington (bot) in branch '3.9': bpo-24888: Clarify subprocess.check_call propagates exceptions if unable to start process (GH-28018) (GH-28223) 2363910
New changeset 31be544 by Miss Islington (bot) in branch '3.10': bpo-24888: Clarify subprocess.check_call propagates exceptions if unable to start process (GH-28018) 31be544
Activity
GeoffreyRoyer commentedon Aug 18, 2015
According to the documentation of the subprocess.check_call function: https://docs.python.org/3/library/subprocess.html#subprocess.check_call
It would be nice to notify the reader that this function can raise FileNotFoundException. It is raised in case when the binary one wants to call does not exist.
Example:
bitdancer commentedon Aug 18, 2015
We don't in general document all the exceptions that can be raised by a piece of code. This could be an edge case, though. Let's see what others thing.
bitdancer commentedon Aug 18, 2015
think.
iritkatriel commentedon Jun 18, 2021
The FileNotFoundException exception is coming from the Popen call, and the docs for subprocess.check_call already mention that it delegates to Popen.
There are quite a few different exceptions that Popen could raise, so I think David's general comment is valid, it would not make sense to mention just this one, or to try and list all of them.
iritkatriel commentedon Jun 19, 2021
That said, the current wording does seem to imply that only CalledProcessErrors can be raised by this function so it might be worth clarifying that other exceptions can occur if the command could not run at all (without enumerating the precise exceptions).
DonnaDia commentedon Aug 27, 2021
Hi, I will work on this. I will create a pull request within 3 days.
padmashreejha717 commentedon Aug 29, 2021
You have to add shell=True to execute a shell command. check_output is trying to find an executable. Try this
ambv commentedon Sep 7, 2021
New changeset 19a304b by DonnaDia in branch 'main':
bpo-24888: Clarify subprocess.check_call propagates exceptions if unable to start process (GH-28018)
19a304b
ambv commentedon Sep 7, 2021
New changeset 2363910 by Miss Islington (bot) in branch '3.9':
bpo-24888: Clarify subprocess.check_call propagates exceptions if unable to start process (GH-28018) (GH-28223)
2363910
miss-islington commentedon Sep 7, 2021
New changeset 31be544 by Miss Islington (bot) in branch '3.10':
bpo-24888: Clarify subprocess.check_call propagates exceptions if unable to start process (GH-28018)
31be544
ambv commentedon Sep 7, 2021
Thanks for the patch, DonnaDia! ✨ 🍰 ✨