Federico
Federico

Reputation: 799

Executing a process with Process.Start() using the path of the process

I'm doing this:

public static void ExecProcess(String path, string filename)
{
    Process proc = new Process();
    proc.StartInfo.FileName = path + "nst.exe";
    proc.StartInfo.Arguments = filename;
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardError = true;
    proc.StartInfo.RedirectStandardOutput = true;

    proc.Start();
    proc.WaitForExit();
    var stringa = proc.StandardOutput.ReadToEnd();
    proc.Close();
}

The problem is my process is using the path of my C# application and not its path. So nst.exe is in C:\Desktop but when I call it with the code above the execution path became C:\\Documents\VisualStudio\MyProject\Debug\.

How can I execute the process in his path?

[EDIT] This is how I call the method:

    public void EseguiOttimizzatore()
    {
        OttimizzatoreService.ExecProcess(@"C:\Users\Developer\Desktop\", _idPlanning.ToString() + ".dat");
    }

Upvotes: 0

Views: 59

Answers (1)

yorah
yorah

Reputation: 2673

Set the WorkingDirectory property of StartInfo:

proc.StartInfo.WorkingDirectory = @"C:\Users\Developer\Desktop\";

Upvotes: 1

Related Questions