I am new to the subprocess module in python.
The documentation provided this example:
>>> subprocess.check_output(["echo", "Hello World!"]) b'Hello World!\n' What I tried is:
>>> import subprocess >>> subprocess.check_output(["cd", "../tests", "ls"]) /usr/bin/cd: line 4: cd: ../tests: No such file or directory Traceback (most recent call last): File "<input>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 620, in check_output raise CalledProcessError(retcode, process.args, output=output) subprocess.CalledProcessError: Command '['cd', '../tests', 'ls']' returned non-zero exit status 1 I am confused because this is my file structure:
/proj /cron test_scheduler.py /tests printy.py test1.py test2.py ... These are my other attempts as well:
>>> subprocess.check_output(["cd", "../tests", "python", "printy.py"]) /usr/bin/cd: line 4: cd: ../tests: No such file or directory Traceback (most recent call last): File "<input>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 620, in check_output raise CalledProcessError(retcode, process.args, output=output) subprocess.CalledProcessError: Command '['cd', '../tests', 'python', 'printy.py']' returned non-zero exit status 1 >>> subprocess.check_output(["cd", "../tests;", "ls"]) /usr/bin/cd: line 4: cd: ../tests;: No such file or directory Traceback (most recent call last): File "<input>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 620, in check_output raise CalledProcessError(retcode, process.args, output=output) subprocess.CalledProcessError: Command '['cd', '../tests;', 'ls']' returned non-zero exit status 1