从 SteamCMD 控制台获取实时输出 C#

And*_*szl 5 c# console process stream output

所以主要问题是,我只能在 SteamCmd 终止时以编程方式从它获取输出。预期输出为:

\n\n
Redirecting stderr to \'D:\\User\\Downloads\\TF2Server\\SteamCMD\\logs\\stderr.txt\'\n[  0%] ElA\xc4\x99rhetA\xc4\xb9 frissA\xc5\x9ftA\xc4\x99sek keresA\xc4\x99se...\n[----] TelepA\xc5\x9ftA\xc4\x99s hitelesA\xc5\x9ftA\xc4\x99se...\nSteam Console Client (c) Valve Corporation\n-- type \'quit\' to exit --\nLoading Steam3...[HTTP Remote Control] HTTP server listening on port 27037.\nOK.\n\nConnecting anonymously to Steam Public...Logged in OK\nWaiting for license info...OK\n Initial App state (0x4) installed\n App state (0x20104) validating, progress: 0.00 (0 / 5380081225)\n App state (0x20104) validating, progress: 0.99 (53119962 / 5380081225)\n                               [...]\n App state (0x20104) validating, progress: 92.92 (4999198384 / 5380081225)\n App state (0x20104) validating, progress: 97.35 (5237711118 / 5380081225)\nSuccess! App \'232250\' already up to date.\n
Run Code Online (Sandbox Code Playgroud)\n\n

但它只是重定向此文本:

\n\n
Steam Console Client (c) Valve Corporation\n-- type \'quit\' to exit --\nLoading Steam3...OK.\n\nConnecting anonymously to Steam Public...Logged in OK\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后当它终止时,其余的完全混合在一起:

\n\n
 Waiting for license info...OK\n Initial App state (0x4) installed\n App state (0x20104) validating, progress: 0.02 (1048576 / 5380081225)\n App state (0x20104) validating, progress: 0.98 (52595346 / 5380081225)\n                                  [...]\n App state (0x20104) validating, progress: 93.92 (5053012344 / 5380081225)\n App state (0x20104) validating, progress: 98.00 (5272580703 / 5380081225)\nSuccess! App \'232250\' already up to date.\n[HTTP Remote Control] HTTP server listening on port 27037.\nRedirecting stderr to \'D:\\User\\Downloads\\TF2Server\\SteamCMD\\logs\\stderr.txt\'\n[  0%] El\xc4\x82\xc2\xa9rhet\xc4\xb9\xe2\x80\x98 friss\xc4\x82\xc2\xadt\xc4\x82\xc2\xa9sek keres\xc4\x82\xc2\xa9se...\n[----] Telep\xc4\x82\xc2\xadt\xc4\x82\xc2\xa9s hiteles\xc4\x82\xc2\xadt\xc4\x82\xc2\xa9se...\n
Run Code Online (Sandbox Code Playgroud)\n\n

所以我用谷歌搜索了很多解决方案,然后我发现了这个问题:“ https://github.com/ValveSoftware/Source-1-Games/issues/1684

\n\n

它说,将其添加到代码中可能会解决问题:

\n\n
\n

setvbuf(stdout, (char *)NULL, _IOLBF, 0);

\n
\n\n

我怎样才能在 C# 中做到这一点?

\n\n

这个问题还参考了另一个问题(https://github.com/ValveSoftware/Source-1-Games/issues/352),说:

\n\n
\n

通过 Windows CreateProcess() 函数启动 steamcmd.exe 时,会出现奇怪的行为,并且 steamcmd.exe 会一遍又一遍地生成自身。

\n
\n\n

有什么方法可以捕获这些进程和/或它们的输出吗?或者还有其他想法吗?

\n