Search code examples
c#batch-fileconsole-applicationmessaging

C# console same output from multi batch files


I need a console application to record some events from an other external application. Console application purpose is to display on screen what external app is doing at each steps. This external application only can call an exe with arguments.

Goal is:

  • External do some job
  • Ex call Console with args to display
  • External do some other job
  • Ex call Console with args to display
  • ...

But Console application is closed an reopened at each call. I need a trick to have a console app waiting for messages and displaying it without closing, but I really dont now where to start looking at.

It may be very ligthweight solution, without any install required.

Thanks.

Edit

the external app (silently running) can only do a command "run program ..." at each step (a command line to exe with parameters).

At each step, I must send to my console app some informations to write ouput to user and little more things. I want a unique output, not a new Console app at each step...

The main idea is to have a background running console app waiting messages from the external app to send informations.

Its kind of lauch console app with paramters, dont stop it and recall same with new parameters, but i dont think it is possible.

I cant install tools on the machines, becauses solution may be deployed on many devices in my company, i cant install services or databases on each..

What kind of solution will you use? Can an console application wait for incoming messages and catch them?


Solution

  • There are a number of different approaches to this;

    • Inter Process Communication - May be overkill here
    • Shared Files - Simple but error prone
    • Other shared storage (Database or Messaging Service) - Would probably be my recommended way

    Using the Database method your application will insert 'logs' of each job into a database table. The Console application can then loop with a simple While loop, reading rows and displaying them. This is more scalable as you can use the logs to, for example, restart jobs etc.