17

リモート サーバーで PowerShell スクリプトを実行するために MSDeploy を取得しようとしています。これは私が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.

誰でも解決策を知っていますか?

4

2 に答える 2

21

あなたのシナリオと問題は、この報告された問題に似ています: STDIN がリダイレクトされた場合、PowerShell.exe がハングする可能性があります

この場合は、次の回避策を試してください: 次を使用します-inputformat none

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

次のように.batファイルを呼び出す「偽のmsdeploy」プログラムでこれを試しました:

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 ファイルを呼び出す場合、これが解決策になることを願っています。

于 2010-11-21T17:33:04.760 に答える
2
powershell.exe -file ScriptFile.ps < CON

これにより、文書化されていない機能に頼ることなく問題を解決できます。

于 2012-11-17T16:35:20.757 に答える