Stop using the Process class for CLI interactions in .NET

preview_player
Показать описание


Hello everybody I'm Nick and in this video I will show you how you can control your machine's CLI in an elegant way in C#. .NET's built in Process class is a total mess and really hard to work with so we will be using a Nuget package called CliWrap, to fix all of those problems and add some very nice features on top of it.

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet
Рекомендации по теме
Комментарии
Автор

Being a .NET developer with over 20 years of experience, I am still getting awed over learning new things. Nick does such a great job stretching my knowledge on topics that really matter to my day-to-day work. Nick's examples are spot on and his ramping up from a basic "hello world" to the more advanced is perfect. Excellent topic and something I'll definitely be using.

riplee
Автор

C# devs: This is cursed, I don't like overloaded operators for gimmicks like this
C++ devs with printing using bit-shift operator: Haha, classic

capsey_
Автор

*Summary*

Problem of the video: _Process_ is hard to work with for executing commands in CLI
Proposed solution: use a library called CliWrap (link in desc)

Most important: 1 -> 2 -> 6 -> 5 -> 9 -> 12
Cool stuff: 5, 9, 12

1) Sample code - 3:08
2) _Execute_ can't do stdout/stdin, _ExecuteBufferedAsync_ can - 4:11

3) CliWarp supports parameters, so no need to escape strings - 5:37
4) You can use a builder instead of an array - 6:02

5) CLI events - 7:08
6) Simpler stdout - 10:18
7) Even simpler with an operator - 11:08
8) The *|* operator - 11:24

9) _CancellationToken_ - 12:10

FFmpeg example, Nick doesn't run the code:
10) With the *|* operator -13:12
11) Same but looks more C# - 13:48
12) Process-to-process piping - 14:09, notice the "|" operator from 7) and 8)

deeplerg
Автор

Finally I am ahead of the legendary Nick Chapsas on this one as I have been using it for years and even sucked in the source code so I could make a change I needed to it. Take that Nick: booyeah!! ;-)

matthewsheeran
Автор

Been using this dream-like library for maybe 4 years now? It has made my wrapped CLIs look clean and understand easily for new developers. So happy you covered this gem.

derangedftw
Автор

What a timing! I've started using Process in one of my projects just this week, and this library looks quite interesting.

kacpertonia
Автор

I had and hated to have to deal with the Process class, flags that you have to set correctly to get process output via events... This looks so much better.

lyrion
Автор

Man i build 5 years ago, an entire app on top of CMD, if this library was available, I would build a more stable code and probable this app will still run. Men I am so happy

BrucyCenteio
Автор

Just used this library on a project after discovering it on your channel a while back. It's a joy to use indeed!

emmanueladebiyi
Автор

Thanks for another great video. I discovered CliWrap about 3 years ago and its been my go-to library any time I need to shell out from a process to call another executable. Especially when I need to process the stdout in a specific way. It has many many options for handling stdout.

Movies
Автор

Seems very useful. It would've been nice if you had shown how the equivalent is done using Process class, even just going over pre-written code.

neppe
Автор

OH MY GOD I'm so happy that you make a video for this is for me THE package of 2022!!!!11!!!!

danielsun
Автор

I was skeptical about "is null" syntax, because it didn't felt C# like.
But now I prefer it above "== null" 😆

The cliwrap | looks great, just let it grow on you.

ryan-heath
Автор

The | override is sick! Tyrrrz is awesome!

vekzdran
Автор

Looks real nice. I'm gonna give it a shot the next time I'll need to use Process

docbrown
Автор

That is pretty neat, wish I'd known about it last time I used the Process class. I didn't even think to look for a package for it.

dominicc
Автор

Great video. This looks way easier to use than the Process class. I can't believe I didn't know about it sooner. And that pipe syntax is so sweet; looks like writing PowerShell in C#, and is very intuitive if you've ever written PowerShell. Very cool.

deadlydog
Автор

I've been meaning to try CliWrap for months now. Thanks for this

henry-js
Автор

This library looks incredibly powerful. Didn't know this existed and have needed something like this several times in my projects. Thanks for sharing!

somerandomusernamenobodyhas
Автор

Always learning something new with Nick, great vid!

xavhow