我正在尝试在 NSIS 中运行 PowerShell。当我运行 NSIS 脚本时:
!include "x64.nsh"
Name "nsExec Test"
OutFile "nsExecTest.exe"
ShowInstDetails show
Section "Output to variable"
nsExec::ExecToStack 'powershell -Command "& {Import-Module }" ServerManager'
Pop $0 # return value/error/timeout
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
DetailPrint '"ImportModules" printed: $1'
DetailPrint " Return value: $0"
nsExec::ExecToStack 'powershell -Command "& {Get-WindowsFeature}" Desktop-Experience'
Pop $0 # return value/error/timeout
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
DetailPrint '"GetWindowsFeature" printed: $1'
DetailPrint " Return value: $0"
SectionEnd
当执行到“Import-Module ServerManager”时,PowerShell被启动(可以在TaskManager进程中看到)。但 nsExecTest.exe 悬而未决。
我用谷歌搜索了这个问题,并找到了 Java 的解决方法。https://blogs.oracle.com/vaibhav/entry/not_as_easy_as_we https://blogs.oracle.com/vaibhav/entry/not_as_easy_as_we
有人对 NSIS 中的这个问题有想法吗?
更新:
我简化了我的测试脚本。
!include "x64.nsh"
Name "nsExec Test"
OutFile "nsExecTest.exe"
ShowInstDetails show
Section "Output to variable"
${If} ${RunningX64}
${DisableX64FSRedirection}
nsExec::ExecToStack 'powershell.exe "& "Import-Module ServerManager"'
Pop $0 # return value/error/timeout
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
DetailPrint '"ImportModules" printed: $1'
DetailPrint " Return value: $0"
DetailPrint ""
${EnableX64FSRedirection}
${Else}
${EndIf}
SectionEnd
据我发现,AaronLS 的答案对我不起作用,我找到了这个问题的两个解决方法,与 PowerShell v2 中的错误有关在这里报道 https://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected#(但从未修复):
- 升级到 PowerShell v3 http://technet.microsoft.com/en-us/library/hh847837.aspx#BKMK_InstallingOnWindows7andWindowsServer2008R2
-
从 NSIS 中的文件运行脚本,并指定inputformat none
。由于一个非常奇怪的原因你必须离开two最后一个引号之前有空格nsExec::ExecToStack
:
SetOutPath "$pluginsdir\NSISTemp"
File script.ps1
nsExec::ExecToStack 'powershell -inputformat none -ExecutionPolicy RemoteSigned -File "$pluginsdir\NSISTemp\script.ps1" '
使用宏我写在这里 http://nsis.sourceforge.net/PowerShell_support,这只是一个问题${PowerShellExec} "echo 'hello powershell'"
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)