Proc 0.3.3
See the version list below for details.
dotnet add package Proc --version 0.3.3
NuGet\Install-Package Proc -Version 0.3.3
<PackageReference Include="Proc" Version="0.3.3" />
paket add Proc --version 0.3.3
#r "nuget: Proc, 0.3.3"
// Install Proc as a Cake Addin #addin nuget:?package=Proc&version=0.3.3 // Install Proc as a Cake Tool #tool nuget:?package=Proc&version=0.3.3
Proc
- Wraps
System.Diagnostics.Process
as anIObservable
ProcessObservable
stream based wrapperEventBasedObservableProcess
event based wrapper
- Exposes a super handy static
Proc.Start
for the quick oneliners - Built in support to send
SIGINT
to any process rather thanSIGKILL
(Process.Kill()
)- NOTE: This only works on Windows for the time being and is not the default
Proc.Start
start a process and block using the default timeout of 1 minute
var result = Proc.Start("ipconfig", "/all");
Provide a custom timeout and an IConsoleOutWriter
that can output to console
while this line is blocking. The following example writes stderr
in red.
var result = Proc.Start("ipconfig", TimeSpan.FromSeconds(10), new ConsoleOutColorWriter());
More options can be passed by passing StartArguments
instead to control how the process should start.
var args = new StartArguments("ipconfig", "/all")
{
WorkingDirectory = ..
}
Proc.Start(args, TimeSpan.FromSeconds(10));
The static Proc.Start
has a timeout of 1 minute
if not specified.
result
has the following propeties
Completed
true if the program completed before the timeoutConsoleOut
a list the console out message asLineOut
instances whereError
on each indicating wheter it was written onstderr
or notExitCode
NOTE ConsoleOut
will always be set regardless of whether an IConsoleOutWriter
is provided
ObservableProcess
The heart of it all this is an IObservable<CharactersOut>
. It listens on the output buffers directly and does not wait on
newlines to emit.
To create an observable process manually follow the following pattern:
using (var p = new ObservableProcess(args))
{
p.Subscribe(c => Console.Write(c.Characters));
p.WaitForCompletion(TimeSpan.FromSeconds(2));
}
The observable is cold
untill subscribed and is not intended to be reused or subscribed to multiple times. If you need to
share a subscription look into RX's Publish
.
The WaitForCompletion()
call blocks so that p
is not disposed which would attempt to shutdown the started process.
The default for doing a shutdown is through Process.Kill
this is a hard SIGKILL
on the process.
The cool thing about Proc
is that it supports SIGINT
interoptions as well to allow for processes to be cleanly shutdown.
var args = new StartArguments("ipconfig", "/all")
{
SendControlCFirst = true
};
This will attempt to send a Control+C
into the running process console on windows first before falling back to Process.Kill
.
Linux and OSX support for this flag is still in the works so thats why this behaviour is opt in.
Dealing with byte[]
characters might not be what you want to program against, so ObservableProcess
allows the following as well.
using (var p = new ObservableProcess(args))
{
p.SubscribeLines(c => Console.WriteLine(c.Line));
p.WaitForCompletion(TimeSpan.FromSeconds(2));
}
Instead of proxying byte[]
as they are received on the socket this buffers and only emits on lines.
In some cases it can be very useful to introduce your own word boundaries
public class MyProcObservable : ObservableProcess
{
public MyProcObservable(string binary, params string[] arguments) : base(binary, arguments) { }
public MyProcObservable(StartArguments startArguments) : base(startArguments) { }
protected override bool BufferBoundary(char[] stdOut, char[] stdErr)
{
return base.BufferBoundary(stdOut, stdErr);
}
}
returning true inside BufferBoundary
will yield the line to SubscribeLine()
. This could be usefull e.g if your process
prompts without a new line:
Continue [Y/N]: <no newline here>
A more concrete example of this is when you call a bat file on windows and send a SIGINT
signal it will always prompt:
Terminate batch job (Y/N)?
Which would not yield to SubscribeLines
and block any waithandles unnecessary. ObservableProcess
handles this edgecase
therefor OOTB and automatically replies with Y
on stdin
in this case.
Also note that ObservableProcess
will yield whatever is in the buffer before OnCompleted().
EventBasedObservable
ObservableProcess
's sibbling that utilizes OutputDataReceived
and ErrorDataReceived
and can only emit lines.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6
- No dependencies.
-
.NETStandard 1.3
- System.Diagnostics.Process (= 4.3.0)
- System.Threading.Thread (= 4.3.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Proc:
Package | Downloads |
---|---|
Elastic.Elasticsearch.Managed
Provides an observable ElasticsearchNode abstraction that can be used to wrap an elasticsearch process. Also ships with an cluster abstraction that can start one or more ElasticsearchNode's |
|
Proc.Fs
Dependency free reactive abstraction around Process, exposes handy static methods for the quick one-liners |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Proc:
Repository | Stars |
---|---|
elastic/apm-agent-dotnet
|
|
opensearch-project/opensearch-net
OpenSearch .NET Client
|
Version | Downloads | Last updated |
---|---|---|
0.8.2 | 1,003 | 10/2/2024 |
0.8.1 | 4,966 | 1/16/2024 |
0.8.0 | 638 | 1/15/2024 |
0.7.3 | 541 | 1/8/2024 |
0.7.2 | 516 | 1/7/2024 |
0.7.1 | 418 | 1/6/2024 |
0.7.0 | 421 | 1/5/2024 |
0.6.2 | 66,926 | 8/28/2019 |
0.6.1 | 212,230 | 6/20/2019 |
0.6.0 | 1,227 | 6/20/2019 |
0.5.0 | 1,171 | 6/20/2019 |
0.4.3 | 5,758 | 3/29/2019 |
0.4.2 | 1,279 | 2/13/2019 |
0.4.1 | 1,339 | 11/28/2018 |
0.4.0 | 1,307 | 11/28/2018 |
0.3.8 | 1,324 | 11/27/2018 |
0.3.7 | 14,988 | 8/31/2018 |
0.3.6 | 1,441 | 8/27/2018 |
0.3.5 | 1,402 | 8/27/2018 |
0.3.4 | 1,398 | 8/27/2018 |
0.3.3 | 1,396 | 8/23/2018 |
0.3.2 | 1,478 | 8/17/2018 |
0.3.1 | 1,430 | 8/17/2018 |
0.3.0 | 1,423 | 8/17/2018 |
0.2.1 | 9,780 | 5/30/2018 |
0.2.0 | 1,508 | 5/30/2018 |
0.1.10 | 1,606 | 5/7/2018 |
0.1.9 | 1,416 | 5/7/2018 |
0.1.8 | 1,598 | 5/7/2018 |
0.1.7 | 1,471 | 5/7/2018 |
0.1.6 | 1,541 | 5/7/2018 |
0.1.5 | 1,512 | 5/7/2018 |
0.1.4 | 1,679 | 4/18/2018 |
0.1.3 | 1,584 | 2/17/2018 |
0.1.1 | 1,631 | 2/12/2018 |