Search code examples
pythonbatch-filehttp-redirectpopenwine

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


Solution

  • 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.