从MSdeploy runco​​mmand运行PowerShell不会退出 [英] Running PowerShell from MSdeploy runcommand does not exit

查看:74
本文介绍了从MSdeploy runco​​mmand运行PowerShell不会退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让MSDeploy在远程服务器上执行PowerShell脚本.这就是我执行MSDeploy的方式:

Im am trying to get MSDeploy to execute a PowerShell script on a remote server. This is how i execute MSDeploy:

msdeploy \
  -verb:sync \ 
  -source:runCommand='C:\temp\HelloWorld.bat', \
  waitInterval=15000,waitAttempts=1 \
  -dest:auto,computername=$WebDeployService$Credentials -verbose

HelloWorld.bat包含:

HelloWorld.bat contains:

echo "Hello world!"
powershell.exe C:\temp\WebDeploy\Package\HelloWorld.ps1
echo "Done"

HelloWorld.ps1仅包含:

The HelloWorld.ps1 only contains:

Write-Host "Hello world from PowerShell!"

但是,PowerShell似乎永远不会终止.这是运行msdeploy的输出:

However, it seems like PowerShell never terminates. This is the output from running the msdeploy:

Verbose: Performing synchronization pass #1.
Verbose: Source runCommand (C:\temp\HelloWorld.bat) does not match destination (C:\temp\HelloWorld.bat) differing in attributes (isSource['True','False']). Update pending.
Info: Updating runCommand (C:\temp\HelloWorld.bat).
Info:

Info: C:\temp>echo "Hello world!"
"Hello world!"

C:\temp\WebDeploy>powershell.exe C:\temp\HelloWorld.ps1

Info: Hello world from Powershell!
Info:

Warning: The process 'C:\Windows\system32\cmd.exe' (command line '/c "C:\Users\peter\AppData\Local\Temp\gaskgh55.b2q.bat
"') is still running. Waiting for 15000 ms (attempt 1 of 1).
Error: The process 'C:\Windows\system32\cmd.exe' (command line '/c "C:\Users\peter\AppData\Local\Temp\gaskgh55.b2q.bat"'
) was terminated because it exceeded the wait time.
Error count: 1.

有人知道解决方案吗?

推荐答案

您的情况和问题类似于此报告的问题: 如果重定向了STDIN,则 PowerShell.exe可以挂起.

Your scenario and problem look similar to this reported issue: PowerShell.exe can hang if STDIN is redirected

如果是这种情况,请尝试以下解决方法:使用-inputformat none:

If this is the case then try this workaround: use -inputformat none:

powershell.exe -inputformat none C:\temp\WebDeploy\Package\HelloWorld.ps1

我已经使用伪造的msdeploy"程序尝试了此操作,该程序以如下方式调用.bat文件:

I have tried this with "a fake msdeploy" program that calls the .bat file like this:

using System.Diagnostics;
class Program
{
    static void Main(string[] args)
    {
        ProcessStartInfo si = new ProcessStartInfo();
        si.FileName = "cmd.exe";
        si.Arguments = "/c " + args[0];
        si.RedirectStandardInput = true;
        si.UseShellExecute = false;
        var process = Process.Start(si);
        process.WaitForExit();
    }
}

此演示确实存在与您描述的问题相同的解决方法.如果msdeploy以相同或相似的方式调用.bat文件,则希望这是一个解决方案.

This demo does have the same problem that you describe and the workaround helps. If msdeploy calls the .bat file in the same or similar way then hopefully this is a solution.

这篇关于从MSdeploy runco​​mmand运行PowerShell不会退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆