How to use "wget" command in Linux?

6 次查看(过去 30 天)
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-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