Reputation: 45
How can I create a launcher for a program (or a script) on MSYS2 that does not show me the black window of the terminal?
My link:
msys2_shell.cmd -mingw64 -c /c/myfolder/program.exe
Upvotes: 2
Views: 1661
Reputation: 87486
To run a program in the MSYS2 environment without showing a window, you should right-click on your Desktop or somewhere else in Windows Explorer, select "New", select "Shortcut", and then enter something like this for the shortcut target:
C:\msys64\usr\bin\mintty.exe -w hide /bin/env MSYSTEM=MINGW64 /bin/bash -lc /c/path/to/your_program.exe
Note that there are 4 paths in here. The path to mintty
and your_program.exe
are absolute paths that you will need to adjust. The paths to env
and bash
are relative to your MSYS2 installation directory. Note also that the first path must be a standard Windows path, since Windows expects that when it is running a shortcut.
It might seem odd to use MinTTY
for this, but the first program we launch needs to be some program that was compiled for the Windows subsystem (-mwindows
option to GCC), or else Windows will automatically start a new console when we run the program. We pass the -w hide
option to MinTTY to tell it not to actually show its own window. Everything after that option is interpreted by MinTTY
as a command to run.
So MinTTY will run /bin/env
from the MSYS2 distribution and pass the remainder of the arguments on to it. This is a handy utility that is actually a standard part of Linux as well as MSYS2. It sets the MSYSTEM
environment variable to MINGW64
(which is important later) and then it runs /bin/bash
with the remainder of the command-line arguments. The MSYSTEM
variable selects which of the three MSYS2 environments to use, and the value values for it are MSYS2
, MINGW32
, or MINGW64
.
We pass -l
to Bash so that it acts as a login script, and runs certain startup scripts. In particular, the /etc/profile
script from MSYS2 is essential because it looks at the MSYSTEM
environment variable, sees that it is MINGW64
, and then sets a bunch of other environment variables (e.g. PATH
) to give you the MinGW 64-bit shell environment, or some different environment if you changed MSYSTEM
.
Finally, we pass the name of your program as the main argument to bash
, so it will run that program after running the initialization scripts.
Upvotes: 4