python - subprocess.call doesn't work as expected -


i have following batch file (test.bat)

my.py < commands.txt 

my.py following:

import sys  print sys.stdin.readlines() 

everything works fine if launch batch file command line (from cmd.exe shell in windows 7).

but if try run via subprocess.call function python doesn't work.

how try run python:

import subprocess import os  # doesn't work ! rc = subprocess.call("test.bat", shell=true) print rc 

and error message get:

>my.py  0<commands.txt traceback (most recent call last):   file "c:\users\.....\my.py ", line 3, in <module>     print sys.stdin.readlines() ioerror: [errno 9] bad file descriptor 1 

i'm using python 2.7.2 on 2.7.5 same behavior.

any ideas?

it should be:

rc = subprocess.call(["cmd", "/c", "/path/to/test.bat"]) 

or using shell:

rc = subprocess.call("cmd /c /path/to/test.bat", shell=true) 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -