我可以在64位shell中执行一行特定的脚本,并将输出返回到正在进行的32位shell会话吗



我正在编写一个Powershell脚本,该脚本将集成到为32位Windows机器设计的产品中。因此,在调用时,它将默认在x86 Powershell上运行,甚至在64位机器上也是如此。其中一行需要在64位shell上运行才能获得准确的结果。尝试过这样做:

#Above this is the ongoing script in 32bit session
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
#write-warning "Excecuting the script under 64 bit powershell"
if ($myInvocation.Line) {
[System.IntPtr]::Size
&"$env:systemrootsysnativewindowspowershellv1.0powershell.exe" -NonInteractive -NoProfile 
#Statement block
}else{
&"$env:systemrootsysnativewindowspowershellv1.0powershell.exe" -NonInteractive -NoProfile  $args
#Statement block
}
}
#Below this is the remaining Script in 32 bit session

我无法将控制流传递到新会话并将其收回。它所做的只是在已经运行的32位shell中启动64位shell。有什么可能的方法可以做到这一点,并返回新外壳打印的值?

我可以使用-Command参数来完成。根据您的用例调用相应的shell(32或64(。直接将命令或完整的脚本块传递到Paradishesion中。

#Invoking the 64-bit Powershell shell 
& "$env:systemrootsysnativewindowspowershellv1.0powershell.exe" -NonInteractive -NoProfile -Command 
{ 
# Statement Block  
}

如果需要,可以将输出存储在变量中。一旦返回控件,父shell就会恢复。

查看官方文档中使用-Command参数的其他示例在这里

最新更新