Исходный код вики System. Diagnostics. Process
Редактировал(а) Alexandr Fokin 2023/05/07 13:08
Последние авторы
| author | version | line-number | content |
|---|---|---|---|
| 1 | Process.start: how to get the output? | ||
| 2 | https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output | ||
| 3 | |||
| 4 | EXECUTE A BASH SCRIPT VIA C#/.NET CORE | ||
| 5 | https://jackma.com/2019/04/20/execute-a-bash-script-via-c-net-core/ | ||
| 6 | |||
| 7 | ---- | ||
| 8 | |||
| 9 | |(% style="width:129px" %)Template|(% style="width:1393px" %){{code language="c#"}}ProcessStartInfo info = new ProcessStartInfo(); | ||
| 10 | // fill info ... | ||
| 11 | info.RedirectStandardOutput = true; | ||
| 12 | info.RedirectStandardError = true; | ||
| 13 | |||
| 14 | //token.ThrowIfCancellationRequested(); | ||
| 15 | using Process process = Process.Start(info); | ||
| 16 | try | ||
| 17 | { | ||
| 18 | await process.WaitForExitAsync(token); | ||
| 19 | } | ||
| 20 | catch (OperationCanceledException) | ||
| 21 | { | ||
| 22 | process.Kill(true); | ||
| 23 | await process.WaitForExitAsync(); | ||
| 24 | throw; | ||
| 25 | } | ||
| 26 | |||
| 27 | var outputString = await process.StandardOutput.ReadToEndAsync(); | ||
| 28 | var errorString = await process.StandardError.ReadToEndAsync(); | ||
| 29 | |||
| 30 | if (process.ExitCode == 0) | ||
| 31 | { | ||
| 32 | //Successe | ||
| 33 | } | ||
| 34 | else | ||
| 35 | { | ||
| 36 | //Error | ||
| 37 | }{{/code}} | ||
| 38 | |(% style="width:129px" %)Arguments (args)|(% style="width:1393px" %)[[Command Line Arguments Parser>>doc:Разработка.NET.Библиотеки.Документы.Форматы данных и схемы.Command Line Arguments Parser.WebHome]] | ||
| 39 | |(% style="width:129px" %) |(% style="width:1393px" %) | ||
| 40 | |||
| 41 | |||
| 42 |