2010-11-21 58 views
16

我想讓MSDeploy在遠程服務器上執行PowerShell腳本。這是我如何執行MSDeploy:從MSdeploy runco​​mmand運行PowerShell不會退出

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. 

任何人都知道解決方案嗎?

+0

有關完整源代碼的最終解決方案嗎? – Kiquenet 2012-07-31 07:21:48

回答

20

您的情況和問題類似於此報告的問題: 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文件,那麼希望這是一個解決方案。

+1

-inputformat沒有解決問題!謝謝! – 2010-11-21 20:27:44

+1

根據Powershell 2.0和3.0 [文檔](http://technet.microsoft.com/en-us/library/hh847736.aspx)'None'不是有效的-InputFormat參數,所以此解決方法可能是依靠未定義的行爲。 – 2014-11-14 14:49:47

2
powershell.exe -file ScriptFile.ps < CON 

這樣可以解決問題而不訴諸無證的功能。

+2

這實際上是做什麼的? – Doug 2013-08-04 07:45:50

+2

user1433852 2015-07-05 17:23:56