Тайм-аут Powershell от C# - PullRequest
       0

Тайм-аут Powershell от C#

0 голосов
/ 05 февраля 2020

Я хочу установить тайм-аут для скриптов powershell, которые я запускаю в c#.

Мой код для запуска моих скриптов:

  private void RunPowerShell(string scriptText)
        {
            string tempFile = Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "PinScript.ps1");
            var file = new StreamWriter(tempFile);
            file.AutoFlush = true;
            file.WriteLine(scriptText);
            file.Dispose();

            string output, errors = string.Empty;
            //this is basically a helper method that runs an exe via the command prompt in c#
            //I want to keep this as is and either add an argument to powershell.exe or alter the 
            //.psi scripts themselves
            _cmd.Run(@"powershell.exe",
                            @"-NoProfile -ExecutionPolicy Bypass " + @"& '" + tempFile + "'",
                            out output,
                            out errors);

            Console.WriteLine("Powershell Output: " + output);
            Console.WriteLine("Powershell Errors: " + errors);
            File.Delete(tempFile);
        }

Я вижу, что есть код, который работает для время ожидания сценария здесь , но я не могу понять, как внедрить эту концепцию в то, что у меня есть выше.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...