1

In a nutshell: I want to start a Python (GUI) app in a venv on windows by double-clicking on a start.cmd file. Everything now works, except: I can't get the CMD terminal window disconnected (running in a separate process) from the Python application.

i.e., the CMD window does everything as expected, but then doesn't close. When I close the CMD window manually, it kills the python app. I thought the command START /B "" was supposed to be the same as app & on linux/mac, but apparently not.

As a simplified example, create and save this simple hello_world.py to emulate:

from tkinter import *
root = Tk()
a = Label(root, text="Hello World")
a.pack()
root.mainloop() 

Then copy the below into a Start.cmd file and double-click. With this simple setup, i get the behavior: CMD doesn't close, and if i manually terminate the python gui dies too (i.e., running as subprocess, not independent).

cd /D "%~dp0"

echo Setup Python Virtual Environment
echo (this might take a minute the first time)
python -m venv ./env

echo Start Application...  success is being able to close CMD window, and have hello_world survive.
START /b "" .\env\Scripts\activate &&hello_world.py 

I solved this on the Mac/linux versions in 3 seconds with one character: &
After several hours, Windows is just not working.

Appreciate any thought... thanks!

  • Not the same but related: This is hacky and may not work for your case, but I've had some luck with this script: https://github.com/gbuktenica/PsRun – xdhmoore Mar 21 '21 at 18:53
  • Thanks - I have to distribute this to several hundred internal users, so I was aiming for plain-vanilla windows as possible. i.e., not for me (i run on mac) but for other, non-technical users. Their use-case has to be: double-click something. – Stephen Hilton Mar 21 '21 at 19:11
  • You don't actually need that whole repo. The script itself is pretty simple. That said, it does feel hacky: https://github.com/gbuktenica/PsRun/blob/master/PsRun.vbs – xdhmoore Mar 21 '21 at 19:17
  • Thanks @xdhmoore - i tried out the script you pointed to - as promised it hid the terminal window, but I never saw python pop-up in my task manager as expected... i.e., something failed in handoffs between CMD / VBS / Py. I really don't care if the terminal window appears, i just want a different process for the Python environment so the terminal window will close (or can be closed) after the app starts. On the positive side, you bring up a good point - i could dust off the ol' vbs skills (some 10 years rusty) and take a different approach. – Stephen Hilton Mar 21 '21 at 20:19

0 Answers0