I've tried methods that I have seen without luck and the Docs dont say much about storing the Output. I've tried the below:
import subprocess
f = open(r'/var/log/temp.txt','w')
subprocess.call('cd /var/log/messagelog', shell=True, stdout=f)
f.close()
with open("/var/log/temp.txt",'r') as f:
for line in f:
print line
All I'm trying to do is get the program to recognize that the directory does not exist. ive substituted a simple print statement for the time being. i CANNOT use check_output for this as updating Python on 30 different systems is highly impractical for this. print line should produce: "cd: can't cd to /var/log/messagelog". Hoping this is a rookie mistake I am making here so another set of eyes here would be greatly appreciated.
EDIT: All I'm trying to do here is see if the directory exists and if not, then create the directory. There may be other ways of doing this but everything I've seen points to subprocess. cd is not a program hence why i have to use call instead of Popen.