在python中对Popen使用输入重定向

2024-09-30 14:35:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要在python中的Popen调用中使用stream redirectiton,以便在wine中使用bat文件。我要做这个:

wine32 cmd  < file.bat

当我从终端手动运行它时,它可以工作,但是当我试图从python调用它时:

^{pr2}$

我得到错误:没有这样的文件或目录

怎么处理呢?在

谢谢


Tags: 文件目录cmd终端stream错误手动file
2条回答

也许你可以检查一下这根线。。https://stackoverflow.com/a/5469427/3445802

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

试试这个:

import sys

#...

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

确保wine32的每个参数都是一个单独的列表元素。在

相关问题 更多 >