The most apparent mistake you is using "CMD.EXE". It's obvious from redirection that you don't need to run it in interactive mode. Hence, you use it to run some other application from this process. This would be more than silly. Instead, you should just start the application you need. "CMD.EXE" is not needed, why? This is just one of applications, nothing special about it.
Now, here is what you need basically:
class SomeClass {
public SomeClass() {
someButton.Click += (sender, eventArgs) => {
if (externalProcess == null) {
externalProcess = System.Diagnostics.Process.Start(
fileName,
commandLine);
} else {
externalProcess.Kill();
externalProcess = null;
}
};
}
System.Diagnostics.Process externalProcess;
Button someButton =
string fileName = "someApplication.exe";
string commandLine = ""some command line parameters"";
}
Very typically
SomeClass
would be the class of your main form or main WPF window, or something you use for UI.
—SA