【问题标题】:Curl behaves inconsistently on Windows PowershellCurl 在 Windows Powershell 上的行为不一致
【发布时间】:2021-03-10 21:11:21
【问题描述】:

我正在尝试编写 Windows Powershell 脚本,但例如,当我编写 $ curl wttr.in 时,我得到了预期的输出,但是当我编写 $a=curl wttr.in;echo $a 时,我得到了胡言乱语。我正在使用位于 C:\Windows\System32\ 中的 curl 可执行文件,因为我删除了与 Invoke-WebRequestcurlwget)相关的默认 Powershell 别名。有什么我做错了吗? 这就是我的意思:

curl wttr.in(预期输出)

$a=curl wttr.in;echo $a(错误输出)

【问题讨论】:

  • 除非我查看 curl 结果的 .Content 属性,否则我没有得到任何选项。
  • 另外,给我看wttr.in
  • @JoelCoehoorn 你确定你使用的是位于System32 的 curl 可执行文件吗?看来您可能正在使用 Powershell 的Invoke-WebRequest。试试Get-Alias curl 看看是不是真的。

标签: windows powershell curl


【解决方案1】:

我相信这与编码有关。一种解决方法是在捕获时添加Out-String

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

【讨论】:

  • 它不能为我解决问题。我一直得到相同的输出。
【解决方案2】:

我无法测试它(响应是“不再查询”),但您可以强制输出编码为特定编码 Encode a string in UTF-8 可能需要进行一些测试才能找到正确的输出。

【讨论】:

    猜你喜欢
    • 2011-06-15
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    相关资源
    最近更新 更多