Вывод C# различается в PowerShell и Windows Terminal PSC#

Место общения программистов C#
Ответить
Гость
 Вывод C# различается в PowerShell и Windows Terminal PS

Сообщение Гость »

Почему в C#, когда я вызываю сценарий с помощью PowerShell и захватываю буфер, выходные данные полностью отличаются от результатов, запускаемых в Windows Terminal PS?
Я должен вызывать то же приложение для запуска команды (PowerShell) из C#... как и в Windows Terminal PS.
Я запускаю это приложение C#, открытое с повышенными привилегиями:

Код: Выделить всё

string command = "docker-compose -p wsdd-projects -f C:\Docker-Structure\init.yml up -d --build"

string policy = "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force";

string arguments = $"-NoProfile -Command \"{policy} ; '{command}'\"";

ProcessStartInfo processBuilder = new("powershell")
{
Arguments = arguments,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
Verb = "runas",
CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8
};
Захват вывода с помощью:

Код: Выделить всё

Process process = new() { StartInfo = processBuilder };

process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
if (showOutput) { terminal.AddToTerminal(e.Data); }
output.AppendLine(e.Data);
}
};

process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
if (showOutput) { terminal.AddToTerminal(e.Data);  }
output.AppendLine(e.Data);
}
};

process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();

await process.WaitForExitAsync();
Я получаю этот результат при вызове PS из C#:

Код: Выделить всё

 reverse-proxy Pulled
phpmyadmin Pulled
faef57eae888 Pull complete
989a1d6c052e Pull complete
0705c9c2f22d Pull complete
621478e043ce Pull complete
98246dcca987 Pull complete
bfed8c155cb6 Pull complete
7a7c2e908867 Pull complete
d176994b625c Pull complete
2d8ace6a2716 Pull complete
c70df516383c Pull complete
15e1b44fe4c7 Pull complete
65e50d44e95a Pull complete
77f68910bc0a Pull complete
605dd3a6e332 Pull complete
99ce27188f07 Pull complete
74d64e32c5d5 Pull complete
ef5fc9928b9f Pull complete
163f3256e112 Pull complete
8a1e25ce7c4f Pull complete
e78b137be355 Pull complete
39fc875bd2b2 Pull complete
035788421403 Pull complete
87c3fb37cbf2 Pull complete
c5cdd1ce752d Pull complete
33952c599532 Pull complete
80bad5b02d6c Pull complete
b86cede81497 Pull complete
876ba35ce95b Pull complete
ac8fec215cc8 Pull complete
7795496aa545 Pull complete
4f4fb700ef54 Pull complete
Вместо этого вывода в Терминале PS Windows:

Код: Выделить всё

[+] Running 33/33
✔ reverse-proxy 13 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                   14.3s
✔ 8a1e25ce7c4f Pull complete                                                      8.1s
✔ e78b137be355 Pull complete                                                      8.5s
✔ 39fc875bd2b2 Pull complete                                                      6.9s
✔ 035788421403 Pull complete                                                      7.6s
✔ 87c3fb37cbf2 Pull complete                                                      8.1s
✔ c5cdd1ce752d Pull complete                                                      8.6s
✔ 33952c599532 Pull complete                                                      8.7s
✔ 80bad5b02d6c Pull complete                                                      9.0s
✔ b86cede81497 Pull complete                                                      9.4s
✔ 876ba35ce95b Pull complete                                                      9.8s
✔ ac8fec215cc8 Pull complete                                                      9.6s
✔ 7795496aa545 Pull complete                                                      10.1s
✔ 4f4fb700ef54 Pull complete                                                      10.2s
✔ phpmyadmin 18 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                  18.4s
✔ faef57eae888 Pull complete                                                      2.3s
✔ 989a1d6c052e Pull complete                                                      0.5s
✔ 0705c9c2f22d Pull complete                                                      4.7s
✔ 621478e043ce Pull complete                                                      1.0s
✔ 98246dcca987 Pull complete                                                      3.0s
✔ bfed8c155cb6 Pull complete                                                      2.8s
✔ 7a7c2e908867 Pull complete                                                      3.5s
✔ d176994b625c Pull complete                                                      4.3s
✔ 2d8ace6a2716 Pull complete                                                      4.1s
✔ c70df516383c Pull complete                                                      5.1s
✔ 15e1b44fe4c7 Pull complete                                                      4.8s
✔ 65e50d44e95a Pull complete                                                      5.3s
✔ 77f68910bc0a Pull complete                                                      5.4s
✔ 605dd3a6e332 Pull complete                                                      5.9s
✔ 99ce27188f07 Pull complete                                                      6.1s
✔ 74d64e32c5d5 Pull complete                                                      6.5s
✔ ef5fc9928b9f Pull complete                                                      6.4s
Где эта строка в моем коде? [+] Запуск
А символы ✔ и [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]?

Подробнее здесь: https://stackoverflow.com/questions/781 ... erminal-ps
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»