3

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

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

"With the default settings of None, no redirection will occur; the child’s file handles will be inherited from the parent", thus no need to have stdout, stderr there.
@AnttiHaapala: Ah, ok. As you might guess I haven't played with subprocess much. :) Which reminds me I really should update my old scripts that use os.popen & friends...
@jmmk: stdout=sys.stdout, stderr=sys.stderr are probably unnecessary -- test it.
0

maybe you can check this thread.. https://stackoverflow.com/a/5469427/3445802

from subprocess import Popen
p = Popen("batch.bat", cwd=r"C:\Path\to\batchfolder")
stdout, stderr = p.communicate()

9 Comments

But I call it from linux through wine. Popen("file.bat" ... won't work here
are you call using idle?
What do you mean? I run python script simply via gnome-terminal
why not use idle python in ubuntu? there .bat file can be executed with idle (because idle is the default for Windows). I used to use it if I want to run the .bat file ... if the gnome terminal would be in error, because it obviously does not support the .bat file in gnome terminal.
Not ubuntu. bat may be executed using stream redirecting as I wrote. I need to get '<' stream redirect working
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.