system('wsl sudo ...') does not work

Hi, i'm trying to write a script that executes a few command through wsl on Windows (basically to automatic install libraries from apt and a c++ routine with ./configure and make).
When I use command such as
system('wsl ./configure')
it goes well, but when I use some like
system('wsl sudo apt-get install')
the script runs but never ends (I see always the "pause" button).
Any suggestions on how to fix this? Thanks

댓글 수: 4

Rik
Rik 2022년 6월 15일
You should make sure your system calls avoid interacting with the user. You should also treat each call to system as a different shell (so don't use cd in one and assume that folder in a second call).
I suspect the first one is biting you here.
Francesco Bellelli
Francesco Bellelli 2022년 6월 15일
This only occur when I use wsl. In fact, when I run the same script in unix systems it allows me to insert the root password.
So how can I use “sudo” commands in wsl/how can I allow the user to insert the password and then pass to the system command directly it?
Rik
Rik 2022년 6월 16일
The double layer is apparently a problem. Could there be a way to pipe the password in somehow? That would require you to store the password in a Matlab variable, but I don't really see a way around that myself. (you can use the input function if you don't want to store the password in plain text in your m file)

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

답변 (1개)

Francesco Bellelli
Francesco Bellelli 2022년 6월 16일

0 개 추천

It seems to work now by taking as input from the user his password and then using
system(wsl echo <password> | wsl sudo -S <command>)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 6월 15일

답변:

2022년 6월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by