How to use "wget" command in Linux?

조회 수: 6 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2021년 2월 1일
댓글: Walter Roberson 2025년 1월 31일
I'm trying to run a program that needs to access the "wget" the command as follows:
[result, cmdout] = system('wget -h');
Do you have any suggestions to get it working in Linux?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2025년 1월 24일
편집: MathWorks Support Team 2025년 1월 31일
You can call the “wget” command from MATLAB using the bang (!) operator:
The exclamation point character (!), sometimes called bang, is a shell escape. The character indicates that the rest of the input line is a command to the operating system. Use it to invoke utilities or call other executable programs without quitting MATLAB. To use the exclamation point in a factorial expression, call the factorial function. For example:
>> !wget --content-disposition "<url>"
This will execute the “wget” command as a system command from MATLAB.
Other possible workarounds for using "wget" are as follows:
1) Use the command “web”:
>> web('<url>');
However, it will open a dialog box and will ask you to save. It will require user interaction.
For more information on the function “web”, you can access the release-specific documentation by running the following command in MATLAB R2020b:
>> web(fullfile(docroot, 'matlab/ref/web.html'))
2) Use the command “websave”:
Give a name to the file and specify the type in which you want to save the data.
>> filename = ' eng-hourly-12012012-12312012.csv';
Create a variable named url and assign the URL to the variable from which you want to download the data.
>> url = 'http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=6358&Year=2012&Month=12&Day=14&timeframe=1&submit= Download+Data';
The “websave” function will save the data from the given URL to the specified file.
>> outputfilename = websave(filename,url);
For more information regarding the “websave” function, please follow the documentation link below:
Please follow the link below to search for the required information regarding the current release:
  댓글 수: 2
Walter Roberson
Walter Roberson 2025년 1월 31일
If system('wget') fails, then !wget is not likely to work.
There is no documented difference between using system() and the ! operator.
It is true that the documentation for system() for Unix explicitly talks about looking at the MATLAB_SHELL and SHELL environment variables, and the documentation for the ! operator does not talk about either one of those. However, that does not prove that the ! operator is in any way different in operation -- it could just be weak documentation.
Walter Roberson
Walter Roberson 2025년 1월 31일
More likely the problem is that wget does not happen to be on the search path.
When MATLAB is started from icon, it does not go through the login shell, so any shell environment setup of search paths is skipped. Only the sytem search path routinely assigned to daemons is available.
The fast work-around is to provide the path to the wget command when you system()
The intermediate work-around is to ensure that wget can be found by the system default path (for example putting a link to it in /usr/bin )
The less convenient work-around is to use setenv to augment the search path.
Finally, there are always options to add things to the system default search path; doing so might not be convenient at all.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by