0

I have a command line program which writes output to a file in response to input. I have a C# program that tries many inputs consecutively into the command line program and then reads the output file and returns the text of the output file. This works fine, but I can only run one of my C# program at a time because multiple ones eventually leads to one trying read the file while another trys writing to it. Is there a way I could read the output as it is being written, making it so I don't have to read the file? Or is there another way I could accomplish having multiple instances of the C# program running the command prompt program and reliably getting the output? I cannot edit the command line program.

  • You could make one DLL which writes to the file. As it writes it can fire an event with the to-be-written-text. If your program uses this dll to write and hooks the event, then multiple instances will receive eachother's event. – Measurity Oct 04 '14 at 20:06
  • Have a look at FileSystemWatcher for monitoring a file or directory (http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher(v=vs.110).aspx). – vikas Oct 04 '14 at 20:16
  • you should post the code of how you setup the file streams. and how the programs talk to each other – RadioSpace Oct 04 '14 at 20:19
  • You can redirect console output of your first program to your second program, see http://stackoverflow.com/questions/199528/c-sharp-console-receive-input-with-pipe . This way you only need to call Console.WriteLine, Console.ReadLine – Sergey Volegov Oct 04 '14 at 20:38
  • I have an example up and running but I can't read past the second character entered by the writer app. both apps open a `FileStream` to the same file at the same time successfully! – RadioSpace Oct 04 '14 at 22:26

0 Answers0