Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke MSYS2 Shell from Command Prompt or PowerShell

Tags:

shell

msys2

Starting from Command Prompt or PowerShell (either is fine; I can figure out how to do the other given one), how can I invoke the MSYS2 shell to run a command?

More specific issue

I'm including this information to avoid an XY problem, but I strongly believe this is best solved by the answer to the above (more general) question.

In particular, I'm hoping to write a shell script to update the packages listed in Part III, Step 3 here. So I need something like:

[invoke msys2 bash] -c "pacman -Sy --needed msys2-runtime"

Calling the bash executable directly doesn't work:

C:\>C:\msys64\usr\bin\bash.exe -c "pacman -Sy --needed msys2-runtime"
/usr/bin/bash: pacman: command not found

I assume it's an environment problem. Changing PATH to include the path to MSYS2's bin directory doesn't fix the problem either. When it tries to install a package, bad things happens (nano is just an example):

C:\>bash -c "pacman -Sy --needed --noconfirm nano"
:: Synchronizing package databases...
 mingw32 is up to date
 mingw64 is up to date
 msys is up to date
resolving dependencies...
looking for conflicting packages...

Packages (1) nano-2.3.6-2

Total Installed Size:  1.81 MiB
Net Upgrade Size:      0.17 MiB

:: Proceed with installation? [Y/n]
(1/1) checking keys in keyring                                                                   [########################################################] 100%
(1/1) checking package integrity                                                                 [########################################################] 100%
(1/1) loading package files                                                                      [########################################################] 100%
(1/1) checking for file conflicts                                                                [########################################################] 100%
(1/1) checking available disk space                                                              [########################################################] 100%
(1/1) upgrading nano                                                                             [########################################################] 100%
error: command (/usr/bin/bash /usr/bin/bash -c . /tmp/alpm_shqjUE/.INSTALL; post_upgrade 2.3.6-2 2.3.2-1 ) failed to execute correctly

Trying to invoke the batch file (C:\msys64\msys2_shell.bat) opens a new shell in a new window, which leaves me not knowing whether it failed or succeeded.

So how can I get the shell into MSYS2's normal state?

like image 954
jpmc26 Avatar asked Nov 07 '14 20:11

jpmc26


1 Answers

We're working hard to fix our messy update procedure, we want it to be trouble-free.

You can see some examples of how we invoke MSYS2 from a batch file when we create a new installer in:

https://github.com/Alexpux/MSYS2-packages/blob/master/msys2-installer/make-msys2-installer.bat

But as @StevenPenny suggests,

bash -l -c "pacman ..."

is the correct way.

like image 64
Ray Donnelly Avatar answered Nov 16 '22 01:11

Ray Donnelly