0

I am executing one .net console from another console App. Eg MyTool.exe < input.txt

Where Input.txt will have all the input required by tool.

The input in the input file should be dyanmic, so to achive this.

I created another wrapper console App MyWrapper.exe. This is first crating the input.txt file and then calling the MyTool.exe using .Net Process().

Content of batch file

MyTool.exe < input.txt

var proc = new Process();
proc.StartInfo.FileName = "MyBatchFIle.bat";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();

Now here is the question. Say in case of error or incorrect input, there is possibility that MyTool.exe can go to infinite loop.

So I want to detect this kind of error and stop the execution.

My plan is to execute the MyWrapper.exe from Windows scheduler.

Thanks, Siraj

1 Answers1

0

You could wait for the process to finish + Timeout. If the process did not finished within the timeout, you can kill it:

if(!proc.WaitForExit(timeout))
{ 
    proc.Kill();
}

Another option is to communicate with the process via IPC (e.g. named pipes). But that requires the extension of both tools and increases complexity.


A third option is to communicate via files. For instance: having a status file that can be written by 'MyTool.exe' in format similar to "[process_ID] status". Then the wrapper could read that infomation periodically and kill the process, restart it or whatever is needed.

Community
  • 1
  • 1
JanDotNet
  • 3,746
  • 21
  • 30