Reputation: 175
I am trying to run an exe file inside another exe file in C#
That works well, however my problem is the exe that should run inside the other opens another console window, which I need to press "Enter" in, for it to stop after it has done what it does.
Is there a way to do that?
This is the code I have so far.
var proc = new Process();
proc.StartInfo.FileName = "thefile.exe";
proc.Start();
proc.WaitForExit();
var exitCode = proc.ExitCode;
proc.Close();
Thanks
Upvotes: 2
Views: 939
Reputation: 58
Just use cmd to open and terminat the exe / user window.
string executingCommand;
executingCommand= "/C Path\\To\\Your\\.exe"; // the /C terminates after carrying out the command
System.Diagnostics.Process.Start("CMD.exe", executingCommand);
Upvotes: 2
Reputation: 186668
Are looking for the input redirectioning?
int exitCode = -1;
// Put IDisposable into using
using (var proc = new Process()) {
proc.StartInfo.FileName = "thefile.exe";
proc.StartInfo.RedirectStandardInput = true;
proc.Start();
using (StreamWriter inputWriter = proc.StandardInput) {
inputWriter.Write('\n');
}
proc.WaitForExit();
exitCode = proc.ExitCode;
}
Upvotes: 1