我试图在 MSDeploy 命令中的 preSync 调用期间调用 powershell,但 powershell 在调用后不会退出该进程。
命令(来自命令行):
“tools/MSDeploy/msdeploy.exe”-verb:sync -preSync:runCommand="powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command C:/MyInstallPath/deploy.ps1 Set-WebAppOffline Uninstall-Service ",waitInterval =60000 -usechecksum -source:dirPath="build/for-deployment" -dest:wmsvc=BLUEPRINT-X86,username=deployer,password=deployer,dirPath=C:/MyInstallPath
我在这里使用了一个 hack (http://therightstuff.de/2010 /02/06/How-We-Practice-Continously-Integration-And-Deployment-With-MSDeploy.aspx)获取 powershell 进程并终止它,但这不起作用。我还尝试了 taskkill 和 sysinternals 等效项,但没有任何方法可以终止该进程,从而导致 MSDeploy 出错。
该命令已执行,但随后就停留在那里。有什么想法可能导致 powershell 像这样挂起吗?我在网上发现了一些其他类似的问题,但没有答案。
环境是Win 2K3,使用Powershell 2.0。
更新:这是我现在用来调用 powershell 命令的 .vbs 脚本。使用“cscript.exe path/to/script.vbs”调用:
Option Explicit
Dim oShell, appCmd,oShellExec
Set oShell = CreateObject("WScript.Shell")
appCmd = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ""&{ . c:/development/materialstesting/deploy/web/deploy.ps1; Set-WebAppOffline }"" "
Set oShellExec = oShell.Exec(appCmd)
oShellExec.StdIn.Close()
I am trying to invoke powershell during the preSync call in a MSDeploy command, but powershell does not exit the process after it has been called.
The command (from command line):
"tools/MSDeploy/msdeploy.exe" -verb:sync -preSync:runCommand="powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command C:/MyInstallPath/deploy.ps1 Set-WebAppOffline Uninstall-Service ",waitInterval=60000 -usechecksum -source:dirPath="build/for-deployment" -dest:wmsvc=BLUEPRINT-X86,username=deployer,password=deployer,dirPath=C:/MyInstallPath
I used a hack here (http://therightstuff.de/2010/02/06/How-We-Practice-Continuous-Integration-And-Deployment-With-MSDeploy.aspx) that gets the powershell process and kills it but that didn't work. I also tried taskkill and the sysinternals equivalent, but nothing will kill the process so that MSDeploy errors out.
The command is executed, but then just sits there. Any ideas what might be causing powershell to hang like this? I have found a few other similar issues around the web but no answers.
Environment is Win 2K3, using Powershell 2.0.
UPDATE: Here is a .vbs script I use to invoke my powershell command now. Invoke using 'cscript.exe path/to/script.vbs':
Option Explicit
Dim oShell, appCmd,oShellExec
Set oShell = CreateObject("WScript.Shell")
appCmd = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ""&{ . c:/development/materialstesting/deploy/web/deploy.ps1; Set-WebAppOffline }"" "
Set oShellExec = oShell.Exec(appCmd)
oShellExec.StdIn.Close()
发布评论
评论(3)
以防万一有人正在为批处理文件寻找类似的解决方案:
看看这里
http://epeleg.blogspot.com/2010/ 06/solution-to-powershell-never-exists.html
Just in case someone is looking for a similar solution for a batch file:
Have a look here
http://epeleg.blogspot.com/2010/06/solution-to-powershell-never-exists.html
查看提议的本网站上的解决方案。看起来 PowerShell.exe 不想在像这样执行时退出,直到调用进程关闭其标准输入。
Look at the proposed solution on this site. It appears that PowerShell.exe doesn't want to exit when executed like this until its stdin has been closed by the invoking process.
您尝试过使用这个命令吗?停止进程 $pid 。 $pid 是当前 pid 的内置 powershell 变量。我在 server 2008 R2 服务器上运行了这个,用于 codecampserver 项目。您可以在此处查看运行此版本的构建:http://build-oss.headspringlabs.com。我已注意到在预同步中尝试过此操作,但我认为这不会影响远程会话。
Have you tried using this command? stop-process $pid . $pid is a built in powershell variable for the current pid. I have this working on a server 2008 R2 server, for the codecampserver project. You can view the build that runs this here: http://build-oss.headspringlabs.com. I have note tried this from a pre-sync but I do not think that should effect the remote session.