Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start() doesn't work properly

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.

like image 483
Vita1ij Avatar asked Aug 01 '13 22:08

Vita1ij


People also ask

How does process start work?

Start(String, String) Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component.

How do I start a process in VB net?

Start another application using your . NET code As a . NET method, Start has a series of overloads, which are different sets of parameters that determine exactly what the method does. The overloads let you specify just about any set of parameters that you might want to pass to another process when it starts.


1 Answers

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.

like image 131
Reed Copsey Avatar answered Sep 23 '22 02:09

Reed Copsey