0

I am running an exe program within my C# console program, which if I were running it via the CMD, it would write to its own log, plus a few messages to the CMD window. When I read the standardOutput within my program, I am able to see the CMD messages, but the log to which the process should be writing to is not being created. In other words, my external process writes to its own log, which is built into this black box utility, so now that I want to run it from my console program, the log is not being created. Has anyone encountered this issue and have some suggestion as to how it can be resolved? I cannot loose this log as it is the utility's log; separate from my program. Here is a snipped of my code:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = processName;
startInfo.RedirectStandardOutput = true;
startInfo.Arguments = " " + dbName + " " + pw + " " + clientFile;
try
{
  using (Process exeProcess = Process.Start(startInfo))
  {
    using (StreamReader reader = exeProcess.StandardOutput)
    {
       exeProcess.Start();
       exeProcess.WaitForExit();
       string result = reader.ReadToEnd();
       Console.WriteLine(result);
    }
  }
}
catch (Exception e)
{
  Console.WriteLine("Error: " + e);
}
thehme
  • 2,698
  • 4
  • 33
  • 39
  • I have a feeling this might be admin issues, see if [this](http://stackoverflow.com/a/133500/1860561) helps. – gitsitgo Sep 09 '13 at 13:33
  • In a comment below, you mention that you lost the log file, Can you find the log file in another folder? You might need to set the [ProcessStartInfo.WorkingDirectory](http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx). The default is `%SYSTEMROOT%\system32` and the application might have permission to write to that folder. – Black Frog Sep 09 '13 at 14:50
  • @BlackFrog thanks for the comment. I will work on adding the WorkingDirectory to see if this saves the process' log because it is not in the %SYSTEMROOT%\system32 location. – thehme Sep 17 '13 at 19:04

1 Answers1

0

You have to read the result after the process has finished:

 exeProcess.Start();
 exeProcess.WaitForExit();
 string result = reader.ReadToEnd();
 Console.WriteLine(result);
Turbofant
  • 517
  • 11
  • 24
  • Unfortunately changing the order did not work. Perhaps the issue is with defining the actual problem. Let me give an example. Suppose that the DIR command in windows automatically wrote this to a log file in some directory (build into the utility) and now you want to run the DIR command in your console program. The log that would otherwise be written to, had you ran the program in the CMD, is not being created when called by the console program. This is my issue; I've lost the process' log. – thehme Sep 06 '13 at 15:33