-
I have a test child app that reads from Standard Input and prints whatever was received, something like this:
I also have a test parent app that waits for a user to press any key to send a message to the child app's Standard Input. In the parent app, if I run the child app using System.Diagnostics.Process like the code below then the child app correctly prints out
If I replace System.Diagnostics.Process with CliWrap.Command and start the child app like this:
before the parent app reaches |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
If you know the string beforehand, use If you need some sort of live channel, you can also use var source = PipeSource.Create(async (destination, token) =>
{
await WaitUntilYourDataBecomesAvailableAsync();
await destination.WriteAsync(...);
}); You could also create your own stream that has explicit completion. The problem with |
Beta Was this translation helpful? Give feedback.
-
PipeSource.FromString(...) immediately writes the string to Standard Input instead of waiting for a trigger, e.g. user keypress, so it's not quite what I'm looking for. Is there any possibility for Command or CommandTask to expose the underlying Process's StandardInput StreamWriter so that I can write to Standard Input only when I have something to write? |
Beta Was this translation helpful? Give feedback.
-
How I've ended up doing it is to create my own BlockingPipeSource (not sure if this is the right name) using the AsyncCollection blocking collection from Stephen Cleary's Nito.AsyncEx.Coordination Nuget package:
The usage is
|
Beta Was this translation helpful? Give feedback.
How I've ended up doing it is to create my own BlockingPipeSource (not sure if this is the right name) using the AsyncCollection blocking collection from Stephen Cleary's Nito.AsyncEx.Coordination Nuget package: