To the benefit of the others I will give a more general answer related to both git bash and msys bash.
Solution 1: Detach without stdout
Assume you want to detach the app:
"C:\Program Files\MyApp\MyApp.exe"
which does not output any info you want to retrieve to stdout (or stderr).
use in your Windows bash shell:
cmd //c start //D "C:\\Program Files\\MyApp" MyApp.exe arg1 arg2
MyApp will run in a separate window and closing the calling bash shell will not affect it (by and large like a Linux daemon).
As noted, you can't read app messages unless they are dialog messages, therefore this solution fits to GUI applications. Anyway, if MyApp.exe
is instead a Windows batch file like MyApp.cmd
, it will call its cmd.exe host and log there: in short you will read outputs for the .cmd/.bat case.
Mac-like users
The cmd.exe
window will flash-out for an instant. If this is not such cool for you(r users), in the above line replace cmd
with cmdow, NirCmd or the likes.
Solution 2: Detach with stdout
If you want to read logs to stdout and stderr, use:
cmd //c start cmd //k "C:\\Program Files\\MyApp\\MyApp" arg1 arg2
This alternative is mostly advised if MyApp is a console application. Now you get a daemon with a "home". MyApp will run hosted by the second cmd.exe
and you will see here its output.
For a GUI app you end out with two windows: MyApp window and the calling cmd window.
In both cases, exiting MyApp doesn't mean closing the cmd window; while closing the cmd window will only close MyApp console.
If the flashing punch strikes you, here you only need to replace the first cmd
, the second is your daemon's visbile home.
Solution 3: Detach document centric applications
Some documents are closely related to some processing applications, via a mechanism resembling the Linux shebang syntax, but based on Windows' registry; so you open the document without calling the related application.
This behaviour can be emulated in bash and even in a detached style.
As for apps not needing to output to stdout and stderr, opening MyApp.doc with:
cmd //c start //D "C:\\Program Files\\MyApp" MyApp.exe "Path\\to\\MyApp.doc"
can be simplified to:
cmd //c start //D "Path\\to" MyApp.doc
As for apps needing stdout and stderr output,
cmd //c start cmd //k "C:\\Program Files\\MyApp\\MyApp" "Path\\to\\MyApp.doc"
can be reduced to:
cmd //c start cmd //k "Path\\to\\MyApp.doc"