Вопрос

I have program pro1.exe that reads from input file, calculates result and writes it to output file. Now I'm writing program test.exe, that tests it on different tests (fill input, run pro1 using Process.Start() and compares output with supposed)

Problem is following: after executing pro1.exe output file is empty. However, if I run it manually, it writes to output file.

Here is 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 is a full path to exe file.

in debug I see, that process is starting, and ending without errors.

Это было полезно?

Решение

This is often caused by having a different WorkingDirectory. You likely need to set the WorkingDirectory property to match the executable's path.

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top