Consider using new Process API instead of CreateProcess sys-call
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
Hello everyone!
Recently I've introduced some new APIs to `Process` that amongst many things allow for redirecting standard handles to `NUL` (or any other valid handle).
@vcsjones pointed me a while ago to this repo and following code:
https://github.com/dotnet/roslyn/blob/106890564f33f6642b625e99bed73b3e9a15244e/src/Compilers/Shared/BuildServerConnection.cs#L558-L568
Once Roslyn moves to .NET 11+, you could use the new APIs to start the process and avoid the need of performing a direct sys-call:
```csharp
using SafeFileHandle nullFile = File.OpenNullHandle();
startInfo.StandardInputHandle = nullFile;
startInfo.StandardOutputHandle = nullFile;
startInfo.StandardErrorHandle = nullFile;
Process.Start(startInfo);
```
Or even use another upcoming API that does what you seem to be doing right now: start a new process with handles redirected to NUL, dispose resource and report pid.
```csharp
int processId = Process.StartAndForget(startInfo);
```
Contributor guide
Assessment
This issue has not been assessed yet.