How do I get the process ID of a process that is started by cmd line
(which is started by me)?
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 of the
PYTHON_SCRIPT" process?
No comments:
Post a Comment