I have a fortran executable that I’m trying to run with a process. The fortran executable requests a file from the user, performs an operation to find a solution, and afterwards if there are multiple solutions, it will ask the user if the would like to find the most optimal solution. My code here that I have provided seems to always crash when I call wait for input idle, as there doesn’t seem to be a gui. I’m new to using processes so if someone could help me out, that would be appreciated.
Thanks.
Edit: I forgot to mention that the fortran executable generates a text file after to provide results to the user. When I remove the wait for input idle, it no longer crashes but the resulting text file is no longer generated. Is the executable not running properly?
Process exeProcess = new Process();
exeProcess.StartInfo.FileName = @"...\marcus12.exe";
exeProcess.StartInfo.UseShellExecute = false;
exeProcess.StartInfo.RedirectStandardError = true;
exeProcess.StartInfo.RedirectStandardInput = true;
exeProcess.StartInfo.RedirectStandardOutput = true;
exeProcess.Start();
//exeProcess.WaitForInputIdle();
exeProcess.StandardInput.WriteLine(Path.GetFileName(filePath));
//exeProcess.WaitForInputIdle();
exeProcess.StandardInput.WriteLine("Y");
exeProcess.WaitForExit();
WaitForInputIdle() is used when the process you launch is a Windows application with message loop. In your case it’s simple console application.
Therefore all you need is to exclude two WaitForInputIdle() calls from the code: