问题描述
在 powershell 中,出于复杂的原因,应用程序需要一个 6 个字符的字符串作为长异步操作的句柄(例如:abcdef).我使用
In powershell , for a complicated reason an application needs a 6 character string as a sort of handle (Eg: abcdef) for a long asynchronous operation. I perform this using
$replaceHandle = "abcdef"
start-Job -handle $replaceHandle
应用程序将异步作业的状态存储在 $abcdef 中(以 $ 为前缀的字符串)我可以随时通过请求访问作业状态的参数
The application stores the status of the asynchronous job in $abcdef (Prefixes string with $)and i can access parameters of job Status at any time by requesting
Get-Status -ID $abcdef.ID
我的代码中的问题是我无法正确获取此 $abcdef.ID我试过了$($jobVar.ToString()).ID - 这给出了空白/错误maipulating $$jobVar.ID 实际上给 $'abcdef'.ID
Problem for me in my code is i am not able to get this $abcdef.ID properlyI have tried$($jobVar.ToString()).ID - this gives blank/errors outmaipulating $$jobVar.ID actually gives $'abcdef'.ID
我如何设法适当地获取 ($abcdef.ID) 的值?
How do i manage to get value of ($abcdef.ID) appropriately ?
推荐答案
这是因为 $jobVar 首先被解释:
It because $jobVar is first interpreted :
试试:
write-host "the value is $($jobVar.ID)"
这篇关于powershell 将一个变量嵌入到另一个变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!