Proc 0.9.1
Proc
A dependency free System.Diagnostics.Process supercharger.
Proc.Exec()for the quick one-linersProc.Start()for the quick one-liners- Use if you want to capture the console output as well as print these message in real time.
- Proc.Start() also allows you to script StandardIn and react to messages
- Wraps
System.Diagnostics.Processas anIObservableProcessObservablestream based wrapperEventBasedObservableProcessevent based wrapper
- Built in support to send
SIGINTto any process before doing a hardSIGKILL(Process.Kill())- Has to be set using
SendControlCFirst = trueonStartArguments
- Has to be set using
Proc.Exec
Execute a process and blocks using a default timeout of 4 minutes. This method uses the same console session
as and as such will print the binaries console output. Throws a ProcExecException if the command fails to execute.
See also ExecArguments for more options
Proc.Exec("ipconfig", "/all");
Proc.Start
start a process and block using the default timeout of 4 minutes
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 4 minutes if not specified.
result has the following properties
Completedtrue if the program completed before the timeoutConsoleOuta list the console out message asLineOutinstances whereErroron each indicating whether it was written onstderror 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("elasticsearch.bat")
{
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]:
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.
Showing the top 20 packages that depend on Proc.
| Packages | 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
|
16 |
|
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
|
17 |
|
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
|
18 |
|
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
|
19 |
|
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
|
20 |
|
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
|
21 |
.NET Framework 4.6.1
- System.Reactive (>= 5.0.0)
.NET 8.0
- System.Reactive (>= 5.0.0)
.NET Standard 2.0
- System.Reactive (>= 5.0.0)
.NET Standard 2.1
- System.Reactive (>= 5.0.0)
| Version | Downloads | Last updated |
|---|---|---|
| 0.9.1 | 20 | 12/24/2024 |
| 0.9.0 | 17 | 12/26/2024 |
| 0.8.2 | 19 | 12/26/2024 |
| 0.8.1 | 18 | 12/26/2024 |
| 0.8.0 | 16 | 12/26/2024 |
| 0.7.3 | 15 | 12/26/2024 |
| 0.7.2 | 18 | 12/26/2024 |
| 0.7.1 | 17 | 12/26/2024 |
| 0.7.0 | 18 | 12/26/2024 |
| 0.6.2 | 15 | 12/26/2024 |
| 0.6.1 | 19 | 11/26/2024 |
| 0.6.0 | 16 | 12/26/2024 |
| 0.5.0 | 15 | 12/26/2024 |
| 0.4.3 | 16 | 12/26/2024 |
| 0.4.2 | 19 | 12/26/2024 |
| 0.4.1 | 16 | 12/26/2024 |
| 0.4.0 | 16 | 12/26/2024 |
| 0.3.8 | 16 | 12/26/2024 |
| 0.3.7 | 16 | 12/26/2024 |
| 0.3.6 | 18 | 12/26/2024 |
| 0.3.5 | 17 | 12/26/2024 |
| 0.3.4 | 17 | 12/26/2024 |
| 0.3.3 | 16 | 12/26/2024 |
| 0.3.2 | 18 | 12/26/2024 |
| 0.3.1 | 17 | 12/26/2024 |
| 0.3.0 | 18 | 12/26/2024 |
| 0.2.1 | 18 | 12/26/2024 |
| 0.2.0 | 16 | 12/26/2024 |
| 0.1.10 | 18 | 12/26/2024 |
| 0.1.9 | 17 | 12/26/2024 |
| 0.1.8 | 18 | 12/26/2024 |
| 0.1.7 | 16 | 12/26/2024 |
| 0.1.6 | 17 | 12/26/2024 |
| 0.1.5 | 16 | 12/26/2024 |
| 0.1.4 | 17 | 12/26/2024 |
| 0.1.3 | 16 | 12/26/2024 |
| 0.1.1 | 19 | 12/26/2024 |