Process.Start() doesn't work properly
Asked Answered
C

1

8

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.

Candidate answered 1/8, 2013 at 22:54 Comment(0)
M
12

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.

Maharanee answered 1/8, 2013 at 22:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.