【问题标题】:Running PowerShell from MSdeploy runcommand does not exit从 MSdeploy runco​​mmand 运行 PowerShell 不会退出
【发布时间】:2011-05-13 09:33:07
【问题描述】:

我正在尝试让 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 msdeploy webdeploy


【解决方案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 2.0 和 3.0 documentation None 不是有效的 -InputFormat 参数,因此此解决方法可能依赖于未定义的行为。
【解决方案2】:
powershell.exe -file ScriptFile.ps < CON

这解决了问题,而无需求助于未记录的功能。

【讨论】:

  • 这实际上是做什么的?
猜你喜欢
  • 1970-01-01
  • 2012-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-03
相关资源
最近更新 更多