1

I was just wondering really if there was an easy way to redirect the output from a StreamReader (in my case one from a NamedPipeClientStream) to the input of a StreamWriter (in my case the one in Console.Out).

Of course you could do this fairly easily with a simple while loop redirecting the data but at the same time I also want to redirect the console's input to a stream writer and out to the Pipe.

I could do it with threads but it seems a bit of a waste of a thread... So I ask, is there a nice way to link streams together?

Been at this all day and I haven't found an easy way yet :/

JamJar00
  • 339
  • 4
  • 13

1 Answers1

1

From .NET 4.5 on, there is the Stream.CopyToAsync method:

How do I copy the contents of one stream to another?

http://msdn.microsoft.com/en-us/library/system.io.stream.copytoasync.aspx

Community
  • 1
  • 1
Roland Bär
  • 1,720
  • 3
  • 22
  • 33