Curl behaves inconsistently on Windows Powershell

Viewed 149

I'm trying to write a Windows Powershell script but when I write $ curl wttr.in for example, I get the expected output however, when I do $a=curl wttr.in;echo $a I just get gibberish. I'm using the curl executable located in C:\Windows\System32\ since I removed the default Powershell aliases related with Invoke-WebRequest (curl and wget). Is there something I'm doing wrong? Here is what I mean:

curl wttr.in (expected output)

correct output

$a=curl wttr.in;echo $a (wrong output)

wrong output

2 Answers

I believe it has to do with encoding. A workaround would be simply add Out-String when capturing

$a = C:\Windows\system32\curl.exe wttr.in | Out-String
$a

enter image description here

I could not test it (response was "no more querys"), but you can force the output encoding into a specific encoding Encode a string in UTF-8 may take some testing to find the right output.

Related