Borrar filtros
Borrar filtros

Changing the shell for system commands to mingw-w64

24 visualizaciones (últimos 30 días)
Runpu
Runpu el 3 de Oct. de 2022
Respondida: Jeremy Hughes el 29 de Abr. de 2024
Hi community,
I've been trying to use 'system' commands in MATLAB to execute operating system command (from MRtrix3 to be specific). However, to do so I need to change the shell from default to mingw-w64 for my windows laptop, which I've been struggling to do. While I've tryied things like:
setenv MATLAB_SHELL C:\msys2\mingw64.exe
inside my script before calling system comamnds, it doesn't actually work.
I wonder what can I do about this / what i did wrong.
Many thanks in advance
  4 comentarios
dpb
dpb el 3 de Oct. de 2022
Is that documented anywhere, Walter? And what makes them special?
Walter Roberson
Walter Roberson el 4 de Oct. de 2022
Bottom of the system() page discusses MATLAB_SHELL and SHELL environment variables in the Unix section.

Iniciar sesión para comentar.

Respuestas (2)

Shivam
Shivam el 24 de Jun. de 2023
Hi, you can override an environment variable in the system command by modifying the command string. In your case, you want to set the MATLAB_SHELL variable to the path of the MinGW-w64 shell before executing your command.
Here's an example of how you can modify your system command to set the MATLAB_SHELL variable:
myPath = 'C:\msys2\mingw64.exe'; % Path to the MinGW-w64 shell
dosCommand = 'pacman -Su'; % For example
system(['set MATLAB_SHELL=' myPath ' && ' dosCommand])
  1 comentario
Jeremy Hughes
Jeremy Hughes el 29 de Abr. de 2024
MATLAB_SHELL only has an effect on unix platforms. Windows only supports CMD

Iniciar sesión para comentar.


Jeremy Hughes
Jeremy Hughes el 29 de Abr. de 2024
On Windows, the only way to do this is to launch the desired shell with the command as an argument.
I couldn't (quickly) find the argumnents for mingw64 how to do this, but for powershell this would look like:
dosCommand = "dir"; % Dos Command needs to be escaped correctly to pass quotes if needed.
wrappedCommand = sprintf('powershell --command "%s"',dosCommand)
wrappedCommand = 'powershell --command "dir"'
system(wrappedCommand)

Categorías

Más información sobre Scope Variables and Generate Names en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by