I am trying to output the result of the openfiles process to a file but I am not getting any result can someone explain why? I have tried it 2 different ways. If I use the command prompt and run the same process it does display a result to my file.
Update: I added a third method with the change redirectstandardoutput = true I tried this and now I get a file but with no results
Update: I found the problem it is with the build option being set to x86 when doing this on a 64bit system I think it is running the 32bit version of openfiles. I tested by running my app and using the RedirectStandardError stream which I should have been doing in the first place :) and this is what it said "ERROR: The target system must be running a 32 bit OS."
//First Method
using (Process proc = new Process())
{
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "openfiles";
proc.StartInfo.Arguments = "/query /FO CSV /v > " + "\"" + Application.StartupPath + @"\OpenFiles.log" + "\"";
proc.Start();
}
//Second method
using (Process proc = new Process())
{
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "cmd";
proc.StartInfo.Arguments = "/C openfiles /query /FO CSV /v > " + "\"" + Application.StartupPath + @"\OpenFiles.log" + "\"";
proc.Start();
}
//Third method
using (Process proc = new Process())
{
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.FileName = "openfiles";
proc.StartInfo.Arguments = "/query /FO CSV /v";
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
if (output != null)
File.WriteAllText(Path.Combine(Application.StartupPath, "OpenFiles.log"), output);
}