0

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']
2
  • Unless cwd (or .) is in the current PATH you wouldn't have been able to type out ais in the shell and have your program execute, you would have had to type out ./ais. So do the same thing and run Popen(["./ais"]) instead. This of course assumes ais has the executable bit set. Commented Jul 6, 2020 at 14:34
  • Oh wow I thought for sure I had tried that, but yes that was it. Thank you Commented Jul 6, 2020 at 14:34

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.