0
votes

I'm running a program in command mode (behind the scene) and output its data to form window. When the I read specific line (i.e., "run failed") I try to close the program using this code:

 if (line.Contains("run failed"))
  Process[] runProc = Process.GetProcessesByName("abc");
  if (runProc .Length == 1)
         runProc [0].Kill();

In some computers it works fine, in others I receive: "Access Denied". I understand it's concerned with the user privileges.

My question is how can I kill the process differently?

The process runs in tcl mode (don't know if it matters) and I see the last line in the form window output is:

abc%

(where abc is the program). Obviously, it shows the command prompt of the program. If it was running in a command window, I would have typing in the command window:

'quit'

and the program would have ended and terminated.

How can I send a 'quit' to tcl if something went wrong?

1

1 Answers

2
votes

The Tcl command to make the current process cease running is exit. By default it exits “successfully” with code 0; use exit 1 (or a larger number, numbers up to 127 are reasonably portable) to use a non-zero exit code indicate a failure.

It might be worthwhile converting the code that you run in the Tcl subprocess into a script so that termination on error happens automatically. It only doesn't do that when you're running interactively.