NOTE: This only happens when running the script inside VSCode. I'm using Win10.
I have a script that, based on a config file, opens a bunch of windows pointing to specific directories. It also starts up a bunch of 'cmd' windows and sets their 'current' directory as specified.
All of this works but the cmd processes are closed when the script ends. The explorer processes on the other hand are not.
I have tried:
os.system('command with params')
subprocess.Popen('command with params', shell=True, close_fds=True)
Is there a way to get Python to launch a process and not terminate it when the script ends?
Config file:
[DEFAULT]
appName=testApp
browser=brave
url=http://testURL
explorer0=x:/appDir1
explorer1=x:/appDir2
commandPromptInFolder0=x:/workDir1
commandPromptInFolder1=x:/workDir2
[browsers]
brave=C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
chrome=C:\Program Files\Google\Chrome\Application\chrome.exe
[commandHandlers]
cmd=C:\Program Files\ConEmu\ConEmu64.exe
Code:
for i in range(10):
explorerNo = 'explorer{0}'.format(i)
if self.config.has_option('DEFAULT', explorerNo):
s = self.config.get('DEFAULT', explorerNo)
if s != "":
s = s.replace('/', '\\')
ex = r'explorer /select,{0}'.format(s)
print(ex)
subprocess.Popen(ex)
if self.config.has_option('commandHandlers', 'cmd'):
cmd = self.config.get('commandHandlers', 'cmd')
else:
cmd = 'cmd'
for i in range(10):
commandPromptInFolder = 'commandPromptInFolder{0}'.format(i)
if self.config.has_option('DEFAULT', commandPromptInFolder):
s = self.config.get('DEFAULT', commandPromptInFolder)
if s != "":
s = s.replace('/', '\\')
cmd2Run = '{0} -dir "{1}"'.format(cmd, s)
print(cmd2Run)
#os.system(cmd2Run)
subprocess.Popen(cmd2Run)