Send strings from one console application to anoth

2019-07-23 17:19发布

问题:

What I have:

Two console applications (target framework 4). Application A does all the work, B displays status every 10 seconds. A runs through nearly 300,000 sql entries and performs miscellaneous work - output is most verbose and its hard to squeeze in general overview information about progress.

What I need:

My goal would be to have A first execute B and then "send" or pass strings over to B so that it can refresh itself with the new values of those strings. It would provide the user who is observing a good indication of what's going on with the whole operation.

What do you recommend to accomplish this. WCF, named pipes? I guess I could make app A the server and app B a client of some sorts.

Visual example: note that application A has about 10x more text (picture is just example)

回答1:

  • Make B first execute A.
  • A write its verbose logging to standard output.
  • B reads A's standard output (google how you can redirect input/output/err of a process)
  • B aggregate information and write a clean log on its standard output.
  • When A exits, B exits too.

Simple !



回答2:

When one process is spawning another, it can obtain its Standard Input/Output streams, so that you can read, write:

http://www.dotnetperls.com/redirectstandardoutput