سؤال

أنا أحاول الحصول على 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.

أي شخص يعرف الحل؟

هل كانت مفيدة؟

المحلول

سيناريوك ومشكلتك تشبهان هذه المشكلة المبلغ عنها:يمكن شنق PowerShell.exe إذا تم إعادة توجيه Stdin

إذا كان هذا هو الحال ، فحاول هذا الحل: استخدم -inputformat none:

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

لقد جربت هذا من خلال برنامج "A MaphedPloy" الذي يدعو ملف .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 بنفس الطريقة أو المماثلة ، ونأمل أن يكون هذا حلًا.

نصائح أخرى

powershell.exe -file ScriptFile.ps < CON

هذا يحل المشكلة دون اللجوء إلى الميزات غير الموثقة.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top