I have a project with .NET 7. In this way, I run an .exe
file in a part of the project. which takes an input file and produces an output file. But when I want to read the output file i get this error:
System.IO.FileNotFoundException: 'Could not find file
Process.Start(System.AppDomain.CurrentDomain.BaseDirectory @"decoder.exe",
string.Format(" -i \"" input.txt "\" \"" output.txt "\""));
File.ReadAllLines("output.txt");
CodePudding user response:
You probably read the output file before it is created. You have to wait until the execution of the exe file is finished
and then read. If the addresses of the files and the .exe file are done correctly, you can use the following code:
var _process = Process.Start(System.AppDomain.CurrentDomain.BaseDirectory @"decoder.exe",
string.Format(" -i \"" input.txt "\" \"" output.txt "\""));
_process.WaitForExit();
File.ReadAllLines("output.txt");