So, I use my own .NET Process to start up a command line process like so:
ProcessStartInfo startInfo = new ProcessStartInfo();
Process p = new Process();
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = redirectOutput;
startInfo.RedirectStandardError = redirectError;
//startInfo.WindowStyle = ProcessWindowStyle.Hidden; //is this necessary for cmd line commands?
startInfo.RedirectStandardInput = false;
startInfo.UseShellExecute = false;
String arguments = "/C PYTHON_SCRIPT";
startInfo.Arguments = arguments;
String pathToProcess = "cmd.exe";
startInfo.FileName = pathToProcess;
startInfo.WorkingDirectory = workingDirectory;
p.StartInfo = startInfo;
p.Start();
The process executes just fine, and I get its output/errors. The problem comes when I want to kill it off before it is finished executing. Since cmd line technically started off the "PYTHON_SCRIPT" process itself, I don't know what the Process ID of that process is! Since that's the one I really want to kill off (not cmd line), I'm screwed. I have in fact killed off the cmd line process to see if it has any effect, and it doesn't.
Any help would be appreciated.
In case it wasn't clear, the question is: "How do I kill off the PYTHON_SCRIPT (or any other) process?"
EDIT: I'm sorry I wasn't clear... I'm using PYTHON_SCRIPT as a filler. I am starting many different processes this way, not all of which are python scripts. Some are batch files, some are python scripts, some are perl scripts, etc. I would much prefer a generalized solution here.
EDIT 2: The situation is a little more complex than it might appear from the question. For instance, I am using scons to build some code. Using "cmd /C scons" is easy. However, starting the scons process is much more difficult, because it is a python script. I pass in a different working directory, so "python.exe scons.py scons" won't work at all, and neither will "scons.bat scons" since scons.bat needs to find scons.py, and scons.py isn't in my working directory.