Comments (2)
Hi @madelson
Thank you for the insight, understood.
I'll close this.
from medallionshell.
Hi @Wintereise . While I suppose you can technically "re-start" a .NET process object by calling Start
again it feels strange to me to do that since you are really just starting a completely new process. Calling Start
again will blow away the std IO streams (as you are seeing) and could do weird things with subscribed events which makes code that uses this pattern prone to bugs.
MedallionShell takes the approach that processes are one-time events (Commands), e. g. associating each process with a Task
which is not restartable.
Therefore, I think the best way to represent a process that may die with or without MedallionShell is to create an entirely new Command
/Process
object on each restart.
For example, if you want a process that auto-restarts on unexpected failure you could do something like this:
while (true)
{
var command = ConfigureAndRunCommand(...)
.RedirectTo(...);
if ((await command.Task).Success) { break; }
}
In this case, we're taking advantage of a MedallionShell feature which makes sure all output has been written from redirection before allowing the Command
s Task
to finish. This makes sure that we won't hit thread-safety issues if the old and new process were being redirected to the same place.
If we want the ability to kill this loop ourselves, we can easily pass in a CancellationToken
to Run
using options.CancellationToken(...)
. That way, when cancellation is triggered it will (a) kill the process and (b) have the Command
's task flip to the Canceled
state, which will cause an OperationCanceledException
to be thrown, exiting the loop.
from medallionshell.
Related Issues (20)
- Parameters and quotes - wrong implementation HOT 1
- Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. HOT 6
- Mocking Shell in unit tests is not possible HOT 1
- Improve debuggability with "open source defaults"
- The process hangs, console output is limited to 8 kb (MacOS, Windows) HOT 2
- Combining RedirectTo and Timeout HOT 1
- See if we can leverage non-blocking reads (and writes?) on the redirect pipes to support cancellable IO
- Consider `KillStrategy`/`KillOptions` API for smarter process killing
- StandardOutput.ReadLineAsync() breaks when not using console output HOT 2
- This property cannot be used when attaching to already running process HOT 1
- do not set startInfo.Verb = "runas" HOT 1
- Cannot launch process through conhost.exe HOT 4
- Please upload release tags HOT 1
- PipeTo does not work as expected HOT 2
- Can not redirect shell command 'read' HOT 5
- Threading problem, locks other instance files HOT 6
- Command.Wait() inside BackgroundWorker.DoWork() kill the app HOT 8
- how can i do multiple input stream? HOT 5
- MedallionShell memory leak HOT 3
- Redirecting stdout/stderr blocks a thread pool thread for each call HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from medallionshell.