作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我想要实现的目标的准系统代码..
$destinationDir = "subdir1"
#creating tab
$newTab = $psise.PowerShellTabs.Add()
Do
{sleep -m 100}
While (!$newTab.CanInvoke)
#running required script in tab
$newTab.Invoke({ cd $destinationDir})
由于 $destinationDir 是在父选项卡中初始化的,它的范围仅限于它,我在子选项卡中得到以下错误
cd : Cannot process argument because the value of argument "path" is null. Change the value of argument "path" to a non-null value.
如何克服这个问题并使用子选项卡中的值?
最佳答案
简短的回答:你不能。 PowerShell ISE 中的每个选项卡都是使用新的运行空间创建的。没有提供用于将变量注入(inject)此运行空间的方法。
长答案:总有变通办法。这里有两个。
<强>1。使用调用脚本 block 将变量传输到新的运行空间:
$destinationDir = "subdir1"
#creating tab
$newTab = $psise.PowerShellTabs.Add()
Do
{sleep -m 100}
While (!$newTab.CanInvoke)
$scriptblock = "`$destinationDir = `"$($destinationDir)`"
cd `$destinationDir"
#running required script in tab
$newTab.Invoke($scriptblock)
<强>2。使用 en 环境变量:
$env:destinationDir = "subdir1"
#creating tab
$newTab = $psise.PowerShellTabs.Add()
Do
{sleep -m 100}
While (!$newTab.CanInvoke)
#running required script in tab
$newTab.Invoke({ cd $env:destinationDir})
关于powershell - 如何在另一个 session (Powershell ISE 选项卡)中使用一个变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29080146/
我是一名优秀的程序员,十分优秀!