If I run this
test -d a
in Linux command line, it returns nothing and prints no error even if directory a
doesn't exist, because the result is returned via exit code.
But if I want to grab this exit code with Python, I get
import subprocess
subprocess.call('test -d a')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/opt/anaconda3/envs/python27/lib/python2.7/subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "/opt/anaconda3/envs/python27/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/opt/anaconda3/envs/python27/lib/python2.7/subprocess.py", line 1025, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
How to overcome this? Changing command text is not allowed, anly python caller code should change. It shoudl return 0
or 1
depending on directory existence as described in manual.