Home > Software engineering >  Curl different outputs in Powershell and ISE
Curl different outputs in Powershell and ISE

Time:08-05

I am looking to replicate the results of a curl command from Powershell in Powershell_ISE. The command grabs a weather report for a city:

(curl http://wttr.in/Manchester -UserAgent "curl" ).Content

When I run this in powershell, it outputs a neat report that shows me information such as

Partly Cloudy 
24 degrees celcius 
30 KM/H Winds etc

When I run this in powershell_ISE, it outputs the same report but it doesnt appear to resolve the values correctly. I get

Partly Cloudy
38;5;226m 22[0m(38;5;226m24[0m) degrees celcius
38;5;202m30[0m KM/H Winds etc

Is there anything I can do to help _ISE resolve this correctly?

Any help greatly appreciated, many thanks.

CodePudding user response:

The special output is ANSI Escape Sequences for coloring and formatting. In Windows it's typically called Virtual Terminal Escape Sequences.

The console host used in PowerShell ISE doesn't support it (as seen below), so you get the raw data instead of the colors.

> $host

Name             : Windows PowerShell ISE Host
Version          : 5.1.22000.653
InstanceId       : 09d9260c-65f0-4435-9a03-4a3aabf6bd92
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : nb-NO
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

> $host.UI.SupportsVirtualTerminal
False

Nothing Windows PowerShell can do about it. The https://wttr.in API does supports a ?T query to drop the formatting. Try:

(curl "http://wttr.in/Manchester?T" -UserAgent "curl" ).Content

  • Related