1

I want to run lmutil.exe with the arguments -a, -c, and 3400@takd, then put everything that command line prompt generates into a text file. What I have below isn't working.

If I step through the process, I get errors like "threw an exception of type System.InvalidOperationException"

        Process p = new Process();
        p.StartInfo.FileName = @"C:\FlexLM\lmutil.exe";
        p.StartInfo.Arguments = "lmstat -a -c 3400@tkad>Report.txt";
        p.Start();
        p.WaitForExit();

All I want is for the command line output to be written to Report.txt

Brandon
  • 1,058
  • 1
  • 18
  • 42

2 Answers2

2

To get the Process output you can use the StandardOutput property documented here.

Then you can write it to a file:

Process p = new Process();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = @"C:\FlexLM\lmutil.exe";
p.StartInfo.Arguments = "lmstat -a -c 3400@tkad";
p.Start();
System.IO.File.WriteAllText("Report.txt", p.StandardOutput.ReadToEnd());
p.WaitForExit();
p.Close();
Cameron S
  • 2,251
  • 16
  • 18
1

You can't use > to redirect via Process, you have to use StandardOutput. Also note that for it to work StartInfo.RedirectStandardOutput has to be set to true.

Guvante
  • 18,775
  • 1
  • 33
  • 64