Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using input redirection with Popen in python

I need to use stream redirectiton in Popen call in python to use bat file with wine. I need make this:

wine32 cmd  < file.bat

It works when I run it manually from terminal, however when I try to call it from python:

proc = Popen('wine32 cmd < file.bat',stdout = PIPE)

I got error: No such file or directory

How to manage with that?

Thanks

like image 476
jmmk Avatar asked Jan 18 '26 22:01

jmmk


1 Answers

Try this:

import sys

#...

with open('file.bat', 'r') as infile:
    subprocess.Popen(['wine32', 'cmd'], 
        stdin=infile, stdout=sys.stdout, stderr=sys.stderr)

Make sure that each argument to wine32 is a separate list element.

like image 52
PM 2Ring Avatar answered Jan 20 '26 14:01

PM 2Ring