WSL/BASH calls from the system command

45 ビュー (過去 30 日間)
Hugo Zeberg
Hugo Zeberg 2018 年 2 月 10 日
回答済み: Ankur Bose 2018 年 9 月 27 日
Hi!
I have some linux software that I run using the Windows Subsystem for Linux (WSL) that I wish to execute from within MATLAB under Windows 10.
In the windows command prompt I can type, e.g., wsl ls.
But running the same command within MATLAB as
system('wsl ls')
does initally work (in this case shows the content of the folder) but then hangs. No 0 is returned that the command has executed successfully.
Any idea how to solve this?

回答 (3 件)

Ankur Bose
Ankur Bose 2018 年 9 月 27 日
Hello All, This was an issue with Windows 10 WSL that has been fixed in Windows 10 Build 17017. See the below link for more information
If you have Windows 10 Build greater than 17017 or Windows 10 April 2018 Update, you should not see this issue.
You can check your windows version by running the command winver

Matthias Senge
Matthias Senge 2018 年 2 月 12 日
I have the same problem. My bash skript runs successfully, but no 0 is returned. Any help?
  2 件のコメント
Hugo Zeberg
Hugo Zeberg 2018 年 2 月 12 日
編集済み: Hugo Zeberg 2018 年 2 月 12 日
I found a workaround, which is not that pretty but does work.
Call the JAVA runtime directly using
rt = java.lang.Runtime.getRuntime();
pr = rt.exec('wsl YOURCOMMAND');
pr.destroy();
Carlo Monjaraz
Carlo Monjaraz 2018 年 4 月 17 日
I have the same issue, it requires me to press Enter to finish the command, which of course does not allow to run the scripts completely

サインインしてコメントする。


Wei Feng
Wei Feng 2018 年 5 月 4 日
I use the following codes to run bash in the MATLAB and it works.
% bashcmd = 'D:\cygwin64\bin\bash.exe -c ';
% bashcmd = 'D:\MinGW\msys\1.0\bin\bash.exe -c ';
bashcmd = 'bash -c '; % WSL
runcmd = ['"' cmd '"'];
status = system([bashcmd runcmd]);
if (status ~= 0)
error(['Run bash cmd error: ' num2str(status)]);
end
The bash can also be Cygwin or MinGW.

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by