gpt4 book ai didi

powershell - 隐藏 Invoke-WebRequest 的进度

转载 作者:行者123 更新时间:2023-12-02 22:48:59 25 4
gpt4 key购买 nike

如何隐藏 Invoke-WebRequest 的进度显示?我做了很多连续的请求,并有我自己使用的 Write-Progress 显示,所以我不需要每次都在它下面弹出内置的。

我使用自动从 Invoke-WebRequest 的结果创建的 mshtml 结果(IE COM 对象),所以我不能切换到 WebClient 或类似的东西,除非有人提供有关如何从 WebClient 请求获取 mshtml 对象的说明.

最佳答案

使用 $progressPreference 变量。默认情况下,它的值应该为“继续”,除非您在其他地方对其进行了编辑,这会告诉 Powershell 显示进度条。既然你提到你有自己的自定义进度显示,我会在 cmdlet 执行后立即重置它。例如:

$ProgressPreference = 'SilentlyContinue'    # Subsequent calls do not display UI.
Invoke-WebRequest ...
$ProgressPreference = 'Continue' # Subsequent calls do display UI.
Write-Progress ...

有关 about_preference_variables 偏好变量的更多信息。这是 $ProgressPreference 的条目:
$ProgressPreference
-------------------
Determines how Windows PowerShell responds to progress updates
generated by a script, cmdlet or provider, such as the progress bars
generated by the Write-Progress cmdlet. The Write-Progress cmdlet
creates progress bars that depict the status of a command.

Valid values:
Stop: Does not display the progress bar. Instead,
it displays an error message and stops executing.

Inquire: Does not display the progress bar. Prompts
for permission to continue. If you reply
with Y or A, it displays the progress bar.

Continue: Displays the progress bar and continues with
(Default) execution.

SilentlyContinue: Executes the command, but does not display
the progress bar.

关于powershell - 隐藏 Invoke-WebRequest 的进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46247608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com