Domanda

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

È stato utile?

Soluzione

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();

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top