0

I have a simple batch file which has:

python mySript.py

I save the file as .bat, I run it, everything is fine except the cmd window stays. I tried many solutions, but nothing worked.

The python script is a tkinter app, and I want to get the app window only when I run the batch file, not the cmd window (should close automtically after running the batch)

Btw, I tried also START \b, but that didn't help.

Compo
  • 36,585
  • 5
  • 27
  • 39
AhmedWas
  • 1,205
  • 3
  • 23
  • 38
  • Don't know if it helps, but have a look here for possible solutions: https://stackoverflow.com/questions/14626178/how-to-close-the-command-line-window-after-running-a-batch-file – umbe1987 Feb 22 '19 at 10:31
  • I already tried this one, but didn't help also. But thanks for the comment anyway – AhmedWas Feb 22 '19 at 10:33
  • [exit](https://ss64.com/nt/exit.html)? – Stephan Feb 22 '19 at 10:37
  • exit doesn't help, because it stucks at the line `python mySript.py`, it waits for it to finish – AhmedWas Feb 22 '19 at 10:40
  • 1
    `start "" pythonw mySript.py` – Gerhard Feb 22 '19 at 10:47
  • ´start "" pythonw mySript.py´ that closes yes the cmd win, but brings up the powershell win :) – AhmedWas Feb 22 '19 at 11:04
  • Either your script should be called `myScript.pyw` or you should use `pythonw` to run it since it is a windows app.. Then you can use `start` to start it in its own process and your batch file will terminate before the script does. – quamrana Feb 22 '19 at 11:09
  • where does powershell come from? are you calling powershell inside of the python file? If so, that means you use a batch file, to call a python script, that calls powershell?? – Gerhard Feb 22 '19 at 11:20
  • additionally, the attempt to run `start \b` will not work as it expects a forward slash to define the switch. `start /b` – Gerhard Feb 22 '19 at 11:23

1 Answers1

2

When reading the help, via cmd.exe for start /? you will see the first line states:

Starts a separate window to run a specified program or command.

So all you need to do is:

start "" python mySript.py

Which will launch the python script and directly exit the batch file, if launched by double click.

Gerhard
  • 22,678
  • 7
  • 27
  • 43