Process.Start () is not working properly

I have a pro1.exe program that reads from the input file, calculates the result and writes it to the output file. Now I am writing a test.exe program that checks it on different tests (it fills in the input, runs pro1 using Process.Start() and compares the output with the intended one)

The problem is this: after executing pro1.exe output file is empty. However, if I run it manually, it writes the output file.

Here is the code how I execute pro1:

  ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.FileName = _applicationName; processInfo.ErrorDialog = true; processInfo.UseShellExecute = false; processInfo.RedirectStandardOutput = true; processInfo.RedirectStandardError = true; Process proc = Process.Start(processInfo); 

_applicationName - full path to the exe file.

In debugging, I see that the process starts and ends without errors.

+6
source share
1 answer

This is often caused by the presence of another WorkingDirectory . You probably need to set the WorkingDirectory property to the executable path.

Without this, when UseShellExecute == false , the working directory may not be the local path of the application.

+9
source

Source: https://habr.com/ru/post/950856/


All Articles