Langsung ke konten
Skillpedia
API & server (backend)5.8k ยท #14655

process-api-net11

Fungsinya

Skill ini menjelaskan cara memakai API Process baru di .NET 11 untuk menjalankan program eksternal, menangkap outputnya, dan mengelola masa hidupnya. Skill ini untuk pengembang aplikasi .NET 11 yang memulai program lain.

Kapan dipakai

  • โœ“Saat aplikasi .NET 11 Anda perlu menjalankan program eksternal dan menangkap outputnya.
  • โœ“Saat proses anak sebaiknya berhenti otomatis ketika aplikasi induk keluar.
  • โœ“Saat Anda perlu memulai proses terlepas atau mengendalikan handle apa yang diwarisi proses anak.

Link skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet11/skills/process-api-net11/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/dotnet/skills/blob/main/plugins/dotnet11/skills/process-api-net11/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit โ†’

Contoh permintaan ke AI

โ€œDi aplikasi .NET 11 saya, jalankan alat baris perintah, tangkap outputnya berupa teks, dan pastikan alat itu berhenti saat aplikasi saya keluar.โ€

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Agent memakai metode proses baru di .NET 11 yang menangani penungguan dan penangkapan output, lalu mengatur opsi masa hidup yang Anda minta.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Process API Improvements โ€” .NET 11

New APIs added to System.Diagnostics.Process in .NET 11 simplify process management, eliminate boilerplate, and prevent common deadlock patterns when capturing output in .NET 11 or later applications.

When to Use

  • Running or orchestrating external processes in a .NET 11 (or later) project.
  • Needing to start a process, wait for it to exit, and capture its output/error streams without risking deadlocks (Process.RunAndCaptureText[Async]).
  • Wanting to ensure child processes are automatically terminated when the parent process exits (KillOnParentExit).
  • Requiring lightweight, low-overhead process creation via SafeProcessHandle on supported platforms.
  • Requiring fine-grained control over handle inheritance (InheritedHandles) or starting detached processes (StartDetached).

When Not to Use

  • The project targets .NET 10 or earlier โ€” these APIs are not available before .NET 11.
  • The default Process.Start() is sufficient and does not require output capturing or advanced lifecycle rules.

Target Framework

<TargetFramework>net11.0</TargetFramework>

New APIs

Types

Before using the new convenience methods, note the following types. Use the framework types directly:

Type Kind Read-only properties
ProcessExitStatus Sealed class int ExitCode, bool Canceled, PosixSignal? Signal
ProcessTextOutput Sealed class ProcessExitStatus ExitStatus, string StandardOutput, string StandardError, int ProcessId
ProcessOutputLine Readonly struct string Content, bool StandardError

ProcessExitStatus describes the outcome of a completed process. Interpret ExitCode using the external command's contract; there is no universal Success property. ProcessTextOutput contains the exit status, captured output and error text, and process ID. ProcessOutputLine identifies one output line and whether it came from standard error.

High-Level Convenience APIs

Static Methods

The ProcessStartInfo overloads below require UseShellExecute = false, which is the default for .NET.

Process.Run / Process.RunAsync

Starts a process and waits for it to exit, returning the exit status. Does not capture standard output or error. Passing silent: true discards standard output and error by internally redirecting standard handles to the NUL device. On timeout or cancellation, the process is killed.

public static ProcessExitStatus Run(string fileName, IEnumerable<string>? arguments = null, bool silent = false, TimeSpan? timeout = null)
public static Task<ProcessExitStatus> RunAsync(string fileName, IEnumerable<string>? arguments = null, bool silent = false, CancellationToken cancellationToken = default)
public static ProcessExitStatus Run(ProcessStartInfo startInfo, TimeSpan? timeout = null)
public static Task<ProcessExitStatus> RunAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default)
Process.RunAndCaptureText / Process.RunAndCaptureTextAsync

Starts a process, captures both standard output and error, and waits for it to exit. Extremely useful for avoiding deadlocks on stream redirection. On timeout or cancellation, the process is killed.

When using the ProcessStartInfo overloads, the caller is responsible for setting RedirectStandardOutput = true and RedirectStandardError = true on ProcessStartInfo (because BCL APIs cannot modify the input arguments they were given).

public static ProcessTextOutput RunAndCaptureText(string fileName, IEnumerable<string>? arguments = null, TimeSpan? timeout = null)
public static Task<ProcessTextOutput> RunAndCaptureTextAsync(string fileName, IEnumerable<string>? arguments = null, CancellationToken cancellationToken = default)
public static ProcessTextOutput RunAndCaptureText(ProcessStartInfo startInfo, TimeSpan? timeout = null)
public static Task<ProcessTextOutput> RunAndCaptureTextAsync(ProcessStartInfo startInfo, CancellationToken cancellationToken = default)
Process.StartAndForget

There is a common misconception that when a process is disposed, it's also being killed. This is not the case, as Process.Dispose only releases the resources associated with the process, but does not kill it.

To make it easier to start a process without the need to worry about disposing it, Process.StartAndForget was introduced. The method starts an executable, retu

Pertanyaan umum

Apakah ini berfungsi di .NET 10?

Tidak. API ini hanya ada di .NET 11 dan yang lebih baru.

Apakah Process.Start default masih berfungsi?

Ya. Default sudah cukup jika Anda tidak membutuhkan penangkapan output atau aturan masa hidup baru.

Apa yang dilakukan KillOnParentExit?

Opsi itu membuat proses anak berhenti otomatis saat proses induk berakhir.

Detail

Deskripsi asli dari pembuat

Provides guidance on the new System.Diagnostics.Process APIs introduced in .NET 11: Process.Run, Process.RunAndCaptureText, Process.StartAndForget, Process.ReadAllText/Bytes/Lines, KillOnParentExit, InheritedHandles, and StartDetached. USE FOR: starting, orchestrating, or capturing output from external processes in applications targeting net11.0 or later. DO NOT USE FOR: applications targeting .NET 10 or earlier, or basic pre-.NET 11 Process.Start usage without new APIs.

repo: dotnet/skills

Popularitas

Bintang GitHub
5.8k
Peringkat
#14655
Lisensi
MIT
Diperbarui
2/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • โ€ฆ

Skill lain dari repositori ini

Skill serupa