How to use Python to repeatedly call an exe file
To repeatedly call the .exe file in Python, you can use the run() function in the subprocess module. Here is an example code:
import subprocess
def call_exe(file_path):
try:
# 多次调用.exe文件
for i in range(3):
subprocess.run(file_path, shell=True)
print(f"{file_path} 第 {i+1} 次调用成功")
except Exception as e:
print(f"{file_path} 调用失败:{str(e)}")
# 调用.exe文件的路径
exe_path = "path_to_your_exe_file.exe"
# 调用函数
call_exe(exe_path)
In the example code above, the call_exe() function takes a parameter file_path which represents the path of the .exe file to be called. The file is then executed multiple times using the subprocess.run() function, in this case 3 times. The shell=True argument indicates that the command should be run in the shell. After each call is completed, a message indicating success or failure will be printed.