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
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,563 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Need Help: FileNotFoundError:[Errno 2] No such file or directory python202209 5 2,636 Sep-12-2022, 04:50 AM
Last Post: python202209
  FileNotFoundError: [Errno 2] No such file or directory: 5l3y3r 6 8,108 Nov-02-2020, 12:48 PM
Last Post: 5l3y3r
  Shutil FileNotFoundError: Errno 2 Help lord_kaiser 8 10,512 Aug-10-2020, 08:45 AM
Last Post: lord_kaiser
  Getting FileNotFoundError: [Errno 2] ,if tries to acees same file from sub-directory pmpinaki 2 2,493 May-04-2020, 03:39 PM
Last Post: pmpinaki
  FileNotFoundError: [Errno 2] No such file or directory saqib1066 23 24,373 Mar-16-2020, 01:25 PM
Last Post: saqib1066
  FileNotFoundError managment sal 2 2,567 Oct-23-2019, 09:18 AM
Last Post: sal
  [split] FileNotFoundError...System cannot find the path specified powerrocker 1 2,047 Oct-03-2019, 09:09 AM
Last Post: buran
Question pdfkit.from_string('Hello!','out.pdf') gives FileNotFoundError sipriusPT 3 9,320 Sep-19-2019, 01:44 PM
Last Post: snippsat
  FileNotFoundError: No such file or no access agatte 2 4,936 Sep-12-2019, 08:48 AM
Last Post: agatte

Forum Jump:

User Panel Messages

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