-3

I am attempting to write a python script that with remove some of the tedium of my everyday actions. Specifically, I always need to run Eclipse, Java VisualVM, and a docker container.

I had planned on importing the os module and just executing a few os.system commands to get everything running:

# set_up.py
# Starts up Eclipse, Java VisualVM, and the docker file s3_dynamodb.yml

import os

os.system("./workspace/eclipse/eclipse")

os.system("./../../usr/bin/jvisualvm")

os.system("docker-compose -f s3_dynamodb.yml up")

I am running into issues where the terminal starts to run eclipse and will not continue with the program until the eclipse instance is terminated. Then it moves on to VisualVM and waits until that is closed, etc. I was wondering if there was a way to execute all three of these commands (well at least eclipse and visualVM) as if I clicked on the icon?

0

If you just want to launch the commands, you don't need Python for that. A simple Bash script is largely enough. Notice the & at the end of every line.

workspace/eclipse/eclipse &
../../usr/bin/jvisualvm &
docker-compose -f s3_dynamodb.yml up &

If, for some reason, you can't use Bash, then Python can actually do that too with POpen:

import subprocess

p1 = subprocess.Popen(['workspace/eclipse/eclipse'])
p2 = subprocess.Popen(['../../usr/bin/jvisualvm'])
p3 = subprocess.Popen(['docker-compose', '-f', 's3_dynamodb.yml', 'up'])

p3.terminate()
p2.terminate()
p1.terminate()
  • Should have refreshed the page before posting my own answer lol. Thanks anyways! – Steven C. Eisemann Jul 21 '16 at 17:04
0

The solution to my problem was as simple as adding on & to the end of each line.

For example, os.system("./workspace/eclipse/eclipse &")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.