Is it possible to run bash scripts in the subsystem from MATLAB on Windows?

조회 수: 10 (최근 30일)
David Haydock
David Haydock 2022년 3월 7일
답변: Swastik Sarkar 2024년 9월 16일
I am using MATLAB on Windows. I run much of my code on here, but I also have to work with some programmes that are only built for Linux. Hence, I have Ubuntu operating as a subsystem, and open a kernel to run these Linux programmes.
I have a pipeline of processing that I work through with the data I use, which essentially goes:
Windows MATLAB scripts > Linux bash commands > Windows MATLAB scripts
It would make things a lot more streamlined if I could have some MATLAB scripts that could perform the bash commands in the subsystem.
Is this even possible? I have only been able to find questions about this which refer to using MATLAB inside Linux, not working from outside and calling bash commands.
Any help would be appreciated.

답변 (1개)

Swastik Sarkar
Swastik Sarkar 2024년 9월 16일
It appears that the goal is to run a MATLAB script on Windows, execute a bash script on Linux via WSL, and then return to MATLAB.
This can be achieved using MATLAB's system command, which allows the execution of OS-native commands directly from MATLAB. To run a bash script within WSL from MATLAB, the following command can be used:
system('wsl bash -c "./script.sh"');
For additional details on the system command, refer to the MATLAB documentation here:
Hope this is helpful!

카테고리

Help CenterFile Exchange에서 Programming Utilities에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by