Python 用于启动和配置多个程序的脚本

Python script to launch and configure several programms

我有一个要在本地调试的应用程序。为此,我必须首先 运行 Consul(这是一个 jar),然后我必须调用 2 两个 REST API 方法,所以我调用两个 POST秒。然后我启动 elasticmq-server 并调用 8 GETs.

目前我在 bat 文件中启动了 jars,但它对 UNIX 毫无用处。我尝试了以下方法:

subprocess.call(['java', '-jar', 'elasticmq-server-0.8.12.jar'], shell=True)

但它并不像我想要的那样工作。我希望 jars 在双击 script.py 后在单独的控制台中启动。可能吗?下面我附上 Minimal Complete Verifiable Example:

我的代码

import subprocess
import time, sys
import requests


subprocess.call(['java', '-jar', 'elasticmq-server-0.8.12.jar'], shell=True)
#call("my.bat") - it works on Windows, but not on Linux
time.sleep(5) #elastic must complete launch - it usually takes 1024 milsec, so I w8 5 just in case.
requests.get('http://localhost:8888/?Action=CreateQueue&QueueName=top-secret')
requests.get('http://localhost:8888/?Action=CreateQueue&QueueName=top-secret2')
requests.get('http://localhost:8888/?Action=CreateQueue&QueueName=top-secret3')
requests.post('http://127.0.0.1:7777/some/catalogs/register', data = {"JSON WITH DATA FOR CONSUL")

预期行为

  1. 双击启动脚本。
  2. 在新控制台中启动 consul,
  3. 在新控制台中启动弹性,
  4. 等待 2-5 秒 - 它已经起作用了。
  5. 调用请求 - 它已经有效。

subprocess 模块特别支持在 Windows 上使用 startupinfo 处理新的 window 创建。 在 *nix 和 Linux 上,您实际上想要生成一个新的终端仿真器,因此您可以这样调用: x-terminal-emulator -e 'bash -c "sleep 20"' ....但这可能不适用于 Mac... 你需要有效地测试你在哪个OS。

我知道一个事实,您不能在 Windows 和 Linux 之间移植上述 call 方法。您必须寻找其他解决方案。