PowerShell / PowerShell/PowerShell
Start-ThreadJob doesn't honor switches or preference variables for Write-Debug, Write-Verbose, Write-Information
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 55.5k
- 派生
- 8.5k
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 88
描述
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Start-ThreadJob doesn't produce output for Information, Verbose, Debug in most cases. Here's a trivial test
Start-ThreadJob -ScriptBlock {
$InformationPreference='Continue'
$VerbosePreference='Continue'
$DebugPreference='Continue'
Write-Host "Starting test"
Write-Information "Write-Information -InformationAction Continue" -InformationAction Continue
Write-Information "Write-Information"
Write-Verbose "Write-Verbose -Verbose" -Verbose
Write-Verbose "Write-Verbose"
Write-Debug "Write-Debug -Debug" -Debug
Write-Debug "Write-Debug"
} | Receive-Job -Wait -AutoRemoveJob
Using Start-Job works. It appears to be that the thread job will only use the preferences variable from the caller, but ignore ones within the script or the switches.
The workaround is to set variables in the calling instance before calling Start-ThreadJob
$InformationPreference='Continue'
$VerbosePreference='Continue'
$DebugPreference='Continue'
Start-ThreadJob ...
This may be related to https://github.com/PowerShell/PowerShell/issues/24016
Expected behavior
Starting test
Write-Information -InformationAction Continue
Write-Information
VERBOSE: Write-Verbose -Verbose
VERBOSE: Write-Verbose
DEBUG: Write-Debug -Debug
DEBUG: Write-Debug
Actual behavior
Starting test
Error details
Environment data
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Darwin 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
复现提供的 Start-ThreadJob 脚本,并将其输出与 Start-Job 进行比较,重点关注 InformationPreference、VerbosePreference 和 DebugPreference 变量,以及 -InformationAction、-Verbose 和 -Debug 开关。使用 Start-ThreadJob 和 Receive-Job 入口点,并查看相关 issue 24016。完成的标准是:无需在调用方设置 preference,即可出现预期的 information、verbose 和 debug 输出。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- shell
- 领域
- cli
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100