We use the subprocess on Windows and Python 2.6 as follows. I am trying to parse a text file using an outdated parser application (suppose parser.py) as follows:
import subprocess
k = subprocess.Popen(['python', 'parser.py', '-f C:\Report1\2011-03-14.txt'],
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print k.communicate()
The problem here is how the file name is passed to the legacy application, where I cannot change the code, but I can only access it using Python.
It is generated with the following error:
IOError: [Errno 22] invalid mode (\'r\') or filename: C:\\Report1\\2011-03-14.txt
When I copy the changed file name (double slash) from traceback to check for existence, the system cannot find it.
Question . How to pass a path as an argument, so that it is processed without conversion to double slashes, so that the system can read the file?
NOTE. os.sep also does not resolve the problem.
EDIT: os.system , , . os.sytem (run_parser.py), (get_parse_status.py), Popens run_parser.py, . , .
.