January 7th, 2013, 10:52 AM
Join Date: Dec 2012
Time spent in forums: 4 h 45 m 30 sec
Reputation Power: 0
Redirect stdout from subprocess Works, but Program Crashes
As always, sorry if this is a basic question. I am running Python 2.6.6 on CentOS 6.2 (64 bit, 32GB of RAM). I want to do an 'ls' command from Python and put the result in a text file. My program accomplishes this but still crashes with an error:
databaseDirectory = './database'
databaseFile = open('databaseList.txt', 'w')
command = subprocess.Popen(['ls', databaseDirectory], stdout=subprocess.PIPE)
fileList = command.communicate()
for chunk in fileList:
for word in re.split('\n', chunk): # This line has an error
if len(word) > 0:
if '.tdf' in word:
The error is 'TypeError: expected string or buffer'
Thanks for the help.