Problem redirecting standard output when running a command line executable from within a windows application
<p>Ok, so as the title implies, I'm having some trouble with this.... When I use the following code it will run but I can't even use > output.txt to get some status of how it ran....</p>

<pre><code>            ProcessStartInfo x = new ProcessStartInfo();
            x.FileName = "somefile.exe";
            x.Arguments = arg1 + " " + arg2 + " " + arg3 + " " + arg4;
            x.WorkingDirectory = workDir;
            x.WindowStyle = ProcessWindowStyle.Hidden;
            Process mde = Process.Start(x);
            mde.WaitForExit();
</code></pre>

<p>Now, what's confusing me is that the moment I add in the code for capturing the input, I get thrown an exception stating that the exe file I'm trying to run does not exist. So when I use....</p>

<pre><code>            ProcessStartInfo x = new ProcessStartInfo();
            x.FileName = "somefile.exe";
            x.Arguments = arg1 + " " + arg2 + " " + arg3 + " " + arg4;
            x.WorkingDirectory = workDir;
            x.WindowStyle = ProcessWindowStyle.Hidden;
            modelf.UseShellExecute = false;
            modelf.RedirectStandardOutput = true;
            Process mde = Process.Start(x);
            mde.WaitForExit();
</code></pre>

<p>What exactly am I doing wrong here. It's like the working directory property can't be set when the useshellexecute property is used, but from what I read that's not the case. So what's going on? Why can it find the file and execute it properly in the first example and not in the second?</p>
