gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 17:58:27 25 4
gpt4 key购买 nike

我需要在Python中的Popen调用中使用流重定向来将bat文件与wine一起使用。我需要做这个:

wine32 cmd  < file.bat

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

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

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

如何管理?

谢谢

最佳答案

试试这个:

import sys

#...

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

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

关于python - 在 python 中使用 Popen 输入重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28125255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com