I am trying to write a Python script to run recursively a program from bash in multiple directories and save(now just display) output in log file.
The problem is that when I try to run that app from home directory just giving the full path of input files it crashes, so I usually run it directly in directory containing input files. I have tried to do this with os.popen() and pexpect but I think most suitable here will be subprocess.
My code:
import subprocess,
from subprocess import Popen, PIPE
subprocess.Popen("$fp "+pcr+" "+dat, cwd=path+dirs[0], stdout=PIPE)
print output.stdout.read()
where pcr and dat are the names of input files.
As I try to run it I obtain following error:
Traceback (most recent call last):
File "file_ed.py", line 47, in <module>
subprocess.Popen("$fp "+pcr+" "+dat, cwd=retval, stdout=PIPE)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
What could be the cause of this problem and how to fix it?