代码之家  ›  专栏  ›  技术社区  ›  Peter Moberg

从MsDeaveRunCu命令运行的PuthBek不退出

  •  17
  • Peter Moberg  · 技术社区  · 14 年前

    我正试图让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.
    

    有人知道解决办法吗?

    2 回复  |  直到 14 年前
        1
  •  21
  •   Roman Kuzmin    14 年前

    您的方案和问题与此报告的问题类似: 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文件,希望这是一个解决方案。

        2
  •  2
  •   Baz    12 年前
    powershell.exe -file ScriptFile.ps < CON
    

    这解决了这个问题,而不需要使用未记录的特性。