Start-ThreadJob中using等方法加载对象至会话失败求助
using:变量的问题 在使用pwsh7.4时,尝试用Start-ThreadJob将对象加载至作业会话,但using:及其他方法均无法正常工作。
尝试方法一:使用using:变量
执行代码:
$job=Start-ThreadJob -name maya6 -InitializationScript {. $using:profile} -ScriptBlock {ichild} # ichild是配置文件中定义的别名
返回错误:
InvalidOperation: A Using variable cannot be retrieved. A Using variable can be used only with Invoke-Command, Start-Job, or InlineScript in the script workflow. When it is used with Invoke-Command, the Using variable is valid only if the script block is invoked on a remote computer.
ichild: The term 'ichild' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
尝试方法二:使用-ArgumentList传递参数
执行代码:
$job=start-threadJob {. $args ; ichild} -ArgumentList $profile # ichild是配置文件中定义的别名
执行receive-job $job时,提示符冻结,且持续出现以下错误:
Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub:https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml
Thank you!Environment
PSReadLine: 2.3.4
PowerShell: 7.4.6
OS: Microsoft Windows 10.0.26100
BufferWidth: 170
BufferHeight: 21Last 49 Keys:
原本以为using:就是专门用于该cmdlet的。
内容的提问来源于stack exchange,提问作者Ralf_Reddings

