This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: FileNotFoundException raised by subprocess.call
Type: behavior Stage: resolved
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: DonnaDia, Geoffrey Royer, docs@python, iritkatriel, lukasz.langa, miss-islington, padmashreejha717, r.david.murray
Priority: normal Keywords: easy, patch

Created on 2015-08-18 14:36 by Geoffrey Royer, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28018 merged DonnaDia, 2021-08-28 20:12
PR 28223 merged miss-islington, 2021-09-07 18:16
PR 28224 merged miss-islington, 2021-09-07 18:17
Messages (11)
msg248773 - (view) Author: Geoffrey Royer (Geoffrey Royer) Date: 2015-08-18 14:36
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:

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'
msg248774 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-08-18 14:43
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.
msg248775 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-08-18 14:44
think.
msg396107 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-18 23:07
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.
msg396142 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-19 17:06
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).
msg400438 - (view) Author: Diana (DonnaDia) * Date: 2021-08-27 18:50
Hi, I will work on this. I will create a pull request within 3 days.
msg400518 - (view) Author: Padmashree Jha (padmashreejha717) Date: 2021-08-29 08:12
You have to add shell=True to execute a shell command. check_output is trying to find an executable. Try this
msg401321 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-07 18:16
New changeset 19a304ba990481f0381a5316096b6b3cf2dff381 by DonnaDia in branch 'main':
bpo-24888: Clarify subprocess.check_call propagates exceptions if unable to start process (GH-28018)
https://github.com/python/cpython/commit/19a304ba990481f0381a5316096b6b3cf2dff381
msg401323 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-07 18:43
New changeset 2363910662cda4dcf574da68b4633b55e5fc0f9c 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)
https://github.com/python/cpython/commit/2363910662cda4dcf574da68b4633b55e5fc0f9c
msg401324 - (view) Author: miss-islington (miss-islington) Date: 2021-09-07 18:44
New changeset 31be544721670516fa9700e088c022ff38b0c5fe by Miss Islington (bot) in branch '3.10':
bpo-24888: Clarify subprocess.check_call propagates exceptions if unable to start process (GH-28018)
https://github.com/python/cpython/commit/31be544721670516fa9700e088c022ff38b0c5fe
msg401325 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-07 18:45
Thanks for the patch, DonnaDia! ✨ 🍰 ✨
History
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 69076
2021-09-07 18:45:06lukasz.langasetstatus: open -> closed
resolution: fixed
messages: + msg401325

stage: patch review -> resolved
2021-09-07 18:44:25miss-islingtonsetmessages: + msg401324
2021-09-07 18:43:51lukasz.langasetmessages: + msg401323
2021-09-07 18:17:03miss-islingtonsetpull_requests: + pull_request26646
2021-09-07 18:16:58miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request26645
2021-09-07 18:16:55lukasz.langasetnosy: + lukasz.langa
messages: + msg401321
2021-08-29 08:12:04padmashreejha717setnosy: + padmashreejha717

messages: + msg400518
versions: - Python 3.4
2021-08-28 20:12:06DonnaDiasetkeywords: + patch
stage: patch review
pull_requests: + pull_request26464
2021-08-27 18:50:55DonnaDiasetnosy: + DonnaDia
messages: + msg400438
2021-06-19 17:06:37iritkatrielsetkeywords: + easy

messages: + msg396142
2021-06-18 23:07:52iritkatrielsetnosy: + iritkatriel
messages: + msg396107
2015-08-18 14:53:32Geoffrey Royersettype: behavior
2015-08-18 14:47:06Geoffrey Royersetversions: + Python 3.4
2015-08-18 14:44:02r.david.murraysetmessages: + msg248775
2015-08-18 14:43:45r.david.murraysetnosy: + r.david.murray
messages: + msg248774
2015-08-18 14:36:31Geoffrey Royercreate