Python Forum
FileNotFoundError when using subprocess
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FileNotFoundError when using subprocess
#1
from subprocess import check_output
output=check_output(["ls", "F:\myData\input"]).decode("utf8")
print(ouptut)
I'm trying to run this code to view the files in this directory and save the results as output but this line is throwing an error upon execution.

Can anyone help me solve this and understand the issue? Sad

Error:
Traceback (most recent call last): File "F:\myData\input\Analysis.py", line 21, in output=check_output(["ls", "F:\myData\input\Analysis.py]).decode("utf8") File "C:\Users\Abhinav\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 336, in check_output **kwargs).stdout File "C:\Users\Abhinav\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 403, in run with Popen(*popenargs, **kwargs) as process: File "C:\Users\Abhinav\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in init restore_signals, start_new_session) File "C:\Users\Abhinav\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 997, in _execute_child startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified
Reply
#2
I set up f:\myData\input
and tried:
>>>from subprocess import check_output
>>>import sys
>>>try:
...    output=check_output(["ls", "F:\myData\input"]).decode("utf8")
... except subprocess.CalledProcessError:
...     print("Unexpected error:", sys.exc_info()[0])
...
>>>
without error.
check for typo, and make sure directory exists
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Help: FileNotFoundError:[Errno 2] No such file or directory python202209 5 5,922 Sep-12-2022, 04:50 AM
Last Post: python202209
  FileNotFoundError: [Errno 2] No such file or directory: 5l3y3r 6 10,324 Nov-02-2020, 12:48 PM
Last Post: 5l3y3r
  Shutil FileNotFoundError: Errno 2 Help lord_kaiser 8 13,878 Aug-10-2020, 08:45 AM
Last Post: lord_kaiser
  FileNotFoundError: [Errno 2] No such file or directory saqib1066 23 31,386 Mar-16-2020, 01:25 PM
Last Post: saqib1066
  FileNotFoundError managment sal 2 3,388 Oct-23-2019, 09:18 AM
Last Post: sal
Question pdfkit.from_string('Hello!','out.pdf') gives FileNotFoundError sipriusPT 3 11,418 Sep-19-2019, 01:44 PM
Last Post: snippsat
  FileNotFoundError: No such file or no access agatte 2 5,845 Sep-12-2019, 08:48 AM
Last Post: agatte
  FileNotFoundError...System cannot find the path specified alex9745 28 26,409 Jul-23-2019, 05:14 AM
Last Post: alex9745
  where is FileNotFoundError at? Skaperen 4 15,378 Oct-03-2017, 01:49 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020