如何使用Python中的子过程两次运行相同的EXE文件

发布于 2025-01-30 08:24:26 字数 634 浏览 3 评论 0原文

我是使用API​​的新手。我需要同时两次运行相同的EXE文件,并使用API​​调用与每个呼叫进行通信。当我只想仅运行一次EXE文件时,我按照以下步骤与它进行通信

import subprocess
import requests

command = "App.exe --restserver"
subprocess.Popen(command)

server_address = "127.0.0.1:5000"

end_point = "/load/"

parameters = {
  "type" = "designI"
}

url = "http://" + server_address + end_point

response_load_designI = requests.post(f"{url}", parameters)

,现在我想再次运行app.exe,但是加载 “ designii” 我仍然有 “ designi” 启动和运行。我想知道第二次运行app.exe的服务器地址是什么?有没有办法强迫第二次运行使用其他地址?我在两个终端尝试分别运行它们,但是在两个终端中,我都得到了相同的服务器地址('127.0.0.1:5000')。

I am new to using APIs. I need to run the same exe file twice at the same time and use API calls to communicate with each one. When I want to run the exe file just once, I follow these steps to communicate with it

import subprocess
import requests

command = "App.exe --restserver"
subprocess.Popen(command)

server_address = "127.0.0.1:5000"

end_point = "/load/"

parameters = {
  "type" = "designI"
}

url = "http://" + server_address + end_point

response_load_designI = requests.post(f"{url}", parameters)

Now I want to run App.exe again but load "designII" this time while I still have "designI" up and running. I am wondering what will be the server address for the 2nd time I run App.exe? Is there a way to force the 2nd run to use a different address? I tried in two terminals to run them separately but in both terminals I got the same server address ('127.0.0.1:5000').

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文