-1

I start the CMD in the background as a process. With the process I start external programs. How do I know, if the external program has exited?

Labo
  • 99
  • 9
  • Are you executing a bat file that runs other programs or are you executing one or more programs from your C# app? It would help if you provided a simple code example that shows exactly what you are trying to do. – Bob Bryan Mar 29 '17 at 02:20
  • FileName = "cmd", Arguments = "/K set prompt=INPUT -$G$S" This is how i run cmd in the background. I then execute programs with process.StandardInput.WriteLine(); And here I need a way to know if the executed program has exited. process.Exited will not help, because the cmd process is running. – Labo Mar 29 '17 at 12:47

1 Answers1

0

If you only run the external program in the batch file you can use Process.Exited event.

process.Exited += Process_Exited;

If not, you can try to find the external process by name to know whether it has exited.

var processes = Process.GetProcessesByName(ExternalProcessName);
bool exited = processes.Length < 1;