So I am currently using the wget
command on windows 10 powershell to download various files. However, when testing this command, files do not actually download.
For example, say I want to download an image, say https://picsum.photos/200, I would use the following command:
PS C:\Users\myname\Desktop> wget https://picsum.photos/200
Which returns an apparently successful result:
StatusCode : 200
StatusDescription : OK
Content : {255, 216, 255, 224...}
RawContent : HTTP/1.1 200 OK
Access-Control-Expose-Headers: Content-Length
Content-Disposition: inline;filename=""
Vary: Origin
Access-Control-Allow-Origin: *
X-Content-Type-Options: nosniff
X-XSS-Protection...
Headers : {[Access-Control-Expose-Headers, Content-Length], [Content-Disposition, inline;filename=""],
[Vary, Origin], [Access-Control-Allow-Origin, *]...}
RawContentLength : 31273
Once this process finishes, I do not observe any new files on my desktop.
However, this code does work:
wget https://picsum.photos/200 -O image.jpg
So what is going on? Why does wget
alone not download the file?
Best Answer
The Powershell implementation of
wget
is notwget
. So it doesn't behave like the UNIX/Linux utilitywget
.As pointed out by user4556274, Powershell uses
wget
andcurl
as aliases for its ownInvoke-WebRequest
.Looking at that (or running
Get-Help wget
under Powershell) it can be seen that the-O [filename]
flag is an acceptable abbreviation for-Output [filename]
, and thatInvoke-WebRequest [URI]
actually returns an object representing a web page rather than writing a file named from the basename of the URL.Thus, this returns "nothing" unless you assign it to a variable or pipe it to another command:
But this delivers a web page "as expected":