-1

I've been trying to use os.system to open Xampp automatically and then run my script made with tkinter. But the problem is that the script stops until I close manually the subprocess.

Here an example.

import os direccion = 'C:/xampp/xampp-control.exe' os.system(direccion) print("Hello world") 

The print() is not working, and just starts to run when I close xampp manually. What can I do to, at the same time is opening xampp, keep running the script?

0

2 Answers 2

0

in python codes executed line by line...

there is two ways to do that:

first and the best way is to wrap the code to a function...

e.g.

def opener(direccion: str): os.system(direccion) 

then use opener function whenever and wherever you want! (e.g. after or abobe your print statement)

second way is to use threading modules...

e.g.

import os import threading import concurrent.futures def opener(direccion: str): os.system(direccion) def printer(): print("Hello World!") with concurrent.futures.ThreadPoolExecutor() as executor: f1 = executor.submit(opener, "C:/xampp/xampp-control.exe") f2 = executor.submit(printer) print(f1.result()) print(f2.result()) 

more info about threading & concurrent.futures modules

Sign up to request clarification or add additional context in comments.

Comments

0

I found a solution working for me:

import os import subprocess def SomeFunction(): subprocess.Popen([myAppWithPath]) time.sleep(5) os.system("taskkill /f /im MyApp.exe") ... # continue with the script... 

A bit roughly written but it´s quite easy to figure out (once you know).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.