Windows - Run process on background after closing cmd
start
should already be the right direction. However, /b
attaches it to the same console. Now the problem is that when a console window is closed, any process associated with this console will also be closed.
You can either use start
without /b
, then it will run in a new console. If you want to run it in the background without a console window though, then you would need to use a VBScript or third-party tool: Run a batch file in a completely hidden way
However, in that case you wouldn't see the stdout/stderr output anymore. You could redirect it to a file though, by wrapping it in a cmd /c your_command > stdout.txt 2> stderr.txt
call and starting this one through one of the aforementioned methods (VBScript, third-party tool, ...).
Alternatively, you could also hide your own console window before you exit. I just wrote a little one-line program which does exactly that (source code is basically ShowWindow(GetConsoleWindow(), SW_HIDE)
): http://share.cherrytree.at/showfile-24286/hide_current_console.exe
This way, you can use start /b
, and when you want to "close" your console (technically hide it), you would run hide_current_console & exit
which would hide the console and then close the cmd.exe process (not the python process) - in one line, since you can't type exit
after the console was already hidden.