Changing the shell for system commands to mingw-w64

조회 수: 27 (최근 30일)
Runpu
Runpu 2022년 10월 3일
댓글: dpb 2024년 11월 21일 14:48
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
dpb
dpb 2022년 10월 3일
Is that documented anywhere, Walter? And what makes them special?
Walter Roberson
Walter Roberson 2022년 10월 4일
Bottom of the system() page discusses MATLAB_SHELL and SHELL environment variables in the Unix section.

댓글을 달려면 로그인하십시오.

답변 (2개)

Shivam
Shivam 2023년 6월 24일
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])
  댓글 수: 2
Jeremy Hughes
Jeremy Hughes 2024년 4월 29일
MATLAB_SHELL only has an effect on unix platforms. Windows only supports CMD
dpb
dpb 2024년 11월 21일 14:48
" Windows only supports CMD"
More precisely, it's that "MATLAB under Windows...", Windows itself does support other command processors such as JP Software's TCC. I've railed about this limitation for years as well...it is a real pain to not be able to use the tools at one's disposal for one's own purposes even if others might not choose to have the other toolset.

댓글을 달려면 로그인하십시오.


Jeremy Hughes
Jeremy Hughes 2024년 4월 29일
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)
  댓글 수: 1
Mariam
Mariam 2024년 11월 19일 21:07
편집: Mariam 2024년 11월 19일 21:07
Hello Jeremy, I tried this approach by running:
command = "echo $PATH";
wrappedCommand = sprintf('mingwenv.cmd --command "%s"',command)
system(wrappedCommand)
but it only opens the mingwenv window and doesnt run any command i give it. do you have any idea what can be done in this case?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by