xenteros xenteros - 3 months ago 15
Java Question

Python script to launch and configure several programms

I've got an application which I want to debug locally. To do so, I have to run

Consul
first (it's a
jar
), then I have to call 2 two
REST API
methods so I call two
POST
s. Then I launch
elasticmq-server
and call
8
GET
s.

At the moment I have launching
jar
s in a
bat
file, but it makes it useless for
UNIX
. I tried the following:

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


but it doesn't work as I want. I expect
jar
s to launch in separate consoles after double-clicking on script.py. Is it possible? Below I attach the
Minimal Complete Verifiable Example
:

My code

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")


Expected behavior


  1. Launch script with a double click.

  2. Launch consul in new console,

  3. Launch elastic in new console,

  4. Wait 2-5 seconds - it already works.

  5. Call requests - it already works.


Answer

I know for a fact, that you cannot port the said call method between Windows and Linux. You have to search for another solution.