Morten Nissov
Morten Nissov

Reputation: 452

File not found error using subprocess in python

I am using python 3.6.9 on my ubuntu 18.04LTS install and trying to use the subprocess library to call a compiled C++ function. The function takes no arguments so I would figure this should work:

subprocess.Popen(["ais"], stdout=subprocess.PIPE)

but doing so returns

>>> Popen(["ais"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'ais': 'ais'

This is a little confusing to me given that calling os.listdir() from the same directory returns:

>>> print(os.listdir())
['COM6 ARPA_A.txt', 'dataStream.py', 'arpa.cpp', 'arpa', 'COM7 AIS.txt', 'ais.cpp', 'ais']

Upvotes: 0

Views: 688

Answers (1)

Jazib Dawre
Jazib Dawre

Reputation: 64

For executing a file you have to use './filename'

from reading your above comment, you have to give executable permission to the file which can be done as:

chmod +x ais

Reason for which is well explained here: https://unix.stackexchange.com/a/4432/399463

Upvotes: 1

Related Questions