Im trying to run more than one different .exe file in console.
i used this code to run it and it works fine.
import os
import subprocess
print('1. App1')
print('2. App2')
print('3. App3')
print('4. App4')
print('5. Exit')
while(True):
run = input('Choose App : ')
if run == '1':
subprocess.call('App1.exe', creationflags=subprocess.CREATE_NEW_CONSOLE)
elif run == '2':
subprocess.call('App2.exe', creationflags=subprocess.CREATE_NEW_CONSOLE)
elif run == '3':
subprocess.call('App3.exe', creationflags=subprocess.CREATE_NEW_CONSOLE)
elif run == '4':
subprocess.call('App4.exe', creationflags=subprocess.CREATE_NEW_CONSOLE)
else
exit()
But the input loop only works when the first app that opened close. So i can input another app to run.
The think is i need to input many app to run in the same time without waiting the first app closed. I tried to add some return fuction but it give me an error message
SyntaxError: 'return' outside function
anyone know how to make it work for opening many app at the same time using subprocess.call
without waiting the first app closed ?
so i tried with Popen but when i choose the input apps it give me an error
File ".exe", line 1 SyntaxError: Non-UTF-8 code starting with '\x90' in file .exe on line 1, but no encoding declared; see python.org/dev/peps/pep-0263 for details
This is the code :
import sys
import os
from subprocess import Popen, PIPE
print('1. App1')
print('2. App2')
while(True):
run = input('Choose App : ')
if run == '1':
run = Popen([sys.executable, "App1.exe"])
run.communicate()
elif run == '2':
run = Popen([sys.executable, "App2.exe"])
run.communicate()
else:
exit()