并行运行多个命令行并打印输出(Python / cmd)

问题描述 投票:0回答:1

我找不到任何答案。其中一个命令行是对exe的调用,其返回值不相关。另一方面,代码的输出对我很重要。我需要与我写的另一个bat文件并行运行这个exe,但我找不到一种方法来获取输出并同时运行它。在python / cmd中有没有办法做到这一点?

python batch-file cmd
1个回答
1
投票

在批处理文件中,您可以使用start XYZ来运行没有阻塞的东西。如果你想使用python(我建议批处理),请使用subprocess模块:

p1 = subprocess.Popen(["my.exe", "arg1", "arg2"])
p2 = subprocess.Popen(["cmd", "/c", "my.bat"])

p1.wait()
p2.wait()
© www.soinside.com 2019 - 2024. All rights reserved.