I have a file with a .run extension, e.g. myfile.run. It is executable, i.e. the permission level has been correctly set.
In a Linux terminal, I can execute it simply by submitting ./myfile.run.
In Python 3.6, I tried executing this same file using the subprocess.run() function but have not been successful. :( I tried:
result = subprocess.run( ['./home/user1/myfile.run'], stdout=subprocess.PIPE )
Traceback (most recent call last):
File "<pyshell#51>", line 1, in <module>
result = subprocess.run( [a], stdout=subprocess.PIPE )
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
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)
NotADirectoryError: [Errno 20] Not a directory: './home/user1/myfile.run'
I tried:
result = subprocess.run( ['/home/user1/myfile.run'], stdout=subprocess.PIPE )
and
result = subprocess.run( '/home/user1/myfile.run', stdout=subprocess.PIPE, shell=True )
Nothing happened.
What is the correct subprocess.run() syntax that I should use? Thanks.
myfile.runoutput things, and have you checkedresult?subprocess.run()in Python 3.6 has thecwdkeyword argument. Therefore theos.chdir()command is not required to solve the wrong directory issue. The correct approach is to set the value of thecwdkeyword argument ofsubprocess.run(). Appreciate you remove your comment that this is a duplicate question as it isn't.