10

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?

Amanda
  • 1,709
  • 2
  • 13
  • 26
Tahoe155
  • 113
  • 1
  • 1
  • 6
  • 2
    Your command looks fine. Where did this implementation of `wget ` come from? – roaima Apr 19 '17 at 16:19
  • 5
    powershell uses `wget` and `curl` as aliases for its own [`Invoke-WebRequest`](https://msdn.microsoft.com/powershell/reference/5.1/microsoft.powershell.utility/Invoke-WebRequest). It's not clear to me that there is any relationship to `wget` other than capturing the typing habits of users of other operating systems. – user4556274 Apr 19 '17 at 16:21
  • 1
    Mmm (it's nice to learn something else new). Arguably though, this is off-topic because we're talking about a Powershell command, not a UNIX/Linux utility. – roaima Apr 19 '17 at 16:28
  • @TimothyMartin initially that was my perspective too, but then I thought that it might be worth leaving open so that we can highlight that `wget` isn't `wget`. (IYSWIM.) – roaima Apr 19 '17 at 17:00
  • @roaima Good point. I'll retract my vote to close. – Timothy Martin Apr 19 '17 at 17:01

1 Answers1

20

The Powershell implementation of wget is not wget. So it doesn't behave like the UNIX/Linux utility wget.

As pointed out by user4556274, Powershell uses wget and curl as aliases for its own Invoke-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 that Invoke-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:

wget http://example.net/path/to/page.html

But this delivers a web page "as expected":

wget http://example.net/path/to/page.html -O page.html
roaima
  • 107,089
  • 14
  • 139
  • 261