Exécution de PowerShell MSdeploy runcommand ne sort pas
-
26-09-2019 - |
Question
Im essaie d'obtenir MSDeploy d'exécuter un script PowerShell sur un serveur distant. Voici comment j'exécute MSDeploy:
msdeploy \
-verb:sync \
-source:runCommand='C:\temp\HelloWorld.bat', \
waitInterval=15000,waitAttempts=1 \
-dest:auto,computername=$WebDeployService$Credentials -verbose
HelloWorld.bat contient:
echo "Hello world!"
powershell.exe C:\temp\WebDeploy\Package\HelloWorld.ps1
echo "Done"
Le HelloWorld.ps1 ne contient que:
Write-Host "Hello world from PowerShell!"
Cependant, il semble que PowerShell se termine jamais. Ceci est le résultat de l'exécution du 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.
Tout le monde connaît une solution?
La solution
Votre regard du scénario et le même problème à cette question du rapport: PowerShell.exe peut se bloquer si STDIN est redirigée
Si tel est le cas, essayez alors cette solution de contournement: utilisez -inputformat none
:
powershell.exe -inputformat none C:\temp\WebDeploy\Package\HelloWorld.ps1
Je l'ai essayé avec le programme « un msdeploy de faux » qui appelle le fichier .bat comme ceci:
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();
}
}
Cette démo a le même problème que vous décrivez et la solution de contournement aide. Si msdeploy
appelle le fichier .bat dans le même ou la même manière alors nous espérons que cela est une solution.
Autres conseils
powershell.exe -file ScriptFile.ps < CON
résoudre le problème sans avoir recours à des fonctions non documentées.