Hello, I am trying to run powershell from C# to execute the command:
powershell -Command "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force ; docker-compose -p wsdd-projects -f C:\Docker-Structure\init.yml up -d --build"
From C# I invoke a process with the capture of the input using:
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();
The problem is that what is captured differs completely from what is seen if it is executed from the Windows terminal:
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
.............
windows terminal output:
[+] 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
Of all the output, what I am not exactly capturing is some data that I simply do not see in the C# capture buffer:
Where is this line in my code? [+] Running
And the characters ✔
and [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]
?
I have tried to implement: | Out-String -Stream
but I keep getting the same result, therefore I must assume that the problem is not the command itself, but rather it is related to how and when docker-compose detects that it should enrich the output output by including the data from progress.
This post is related to: C# output differs between PowerShell and Windows Terminal PS but the answers on this site have not given me any positive or directed results.