powershell - 从 MSdeploy runco​​mmand 运行 PowerShell 不会退出

标签 powershell msdeploy webdeploy

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

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

HelloWorld.bat 包含:

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

HelloWorld.ps1 仅包含:

Write-Host "Hello world from PowerShell!"

但是,PowerShell 似乎永远不会终止。这是运行 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.

有人知道解决办法吗?

最佳答案

您的场景和问题与报告的问题类似: PowerShell.exe can hang if STDIN is redirected

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

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

我已经尝试过使用“一个假的 msdeploy”程序来调用 .bat 文件,如下所示:

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 文件,那么希望这是一个解决方案。

关于powershell - 从 MSdeploy runco​​mmand 运行 PowerShell 不会退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4238192/

相关文章:

powershell - 如何在PowerShell中使用Get-Content和Select-String输出与 'this_string'不匹配的行?

azure - 使用 ARM 更新现有 Web 应用程序部署的最佳实践是什么?

visual-studio - .NET 核心 3.0 : ASPNETCORE_ENVIRONMENT has value Development on publish

powershell - Export-Csv创建一个空文件

parsing - Powershell删除第一个特殊字符实例后的文本

MSDeploy 问题(WMSVC 500 错误)

azure - Web 部署到 azure 时出现 EscapeTextForRegularExpressions 错误

c# - 在 Entity Framework 中使用拦截器时如何禁用它们

csv - 将DataTable转换为CSV

azure - 通过 ARM/msdeploy 部署到 Azure Web App,无需删除现有文件