Esecuzione di PowerShell da MSDeploy RunCommand non esce
-
26-09-2019 - |
Domanda
Im sto cercando di ottenere MSDeploy per eseguire uno script PowerShell su un server remoto. Questo è il modo eseguo MSDeploy:
msdeploy \
-verb:sync \
-source:runCommand='C:\temp\HelloWorld.bat', \
waitInterval=15000,waitAttempts=1 \
-dest:auto,computername=$WebDeployService$Credentials -verbose
HelloWorld.bat contiene:
echo "Hello world!"
powershell.exe C:\temp\WebDeploy\Package\HelloWorld.ps1
echo "Done"
L'HelloWorld.ps1 contiene solo:
Write-Host "Hello world from PowerShell!"
Tuttavia, sembra che PowerShell non termina. Questa è l'uscita dalla gestione del 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.
Qualcuno sa una soluzione?
Soluzione
Il vostro scenario e di problem aspetto simile a questo problema segnalato: PowerShell.exe può appendere se STDIN viene reindirizzato
Se questo è il caso allora provare questa soluzione: l'uso -inputformat none
:
powershell.exe -inputformat none C:\temp\WebDeploy\Package\HelloWorld.ps1
Ho provato questo con il programma "un falso msdeploy" che richiama il file .bat in questo modo:
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();
}
}
Questa demo ha lo stesso problema che si descrive e la soluzione aiuta. Se msdeploy
chiama il file .bat nella stessa o simile modo, allora speriamo che questa è una soluzione.
Altri suggerimenti
powershell.exe -file ScriptFile.ps < CON
Questo risolve il problema senza ricorrere a funzionalità non documentate.