1

我想使用参数 -a、-c 和 3400@takd 运行 lmutil.exe,然后将命令行提示符生成的所有内容放入文本文件中。我下面的内容不起作用。

如果我逐步完成该过程,我会收到诸如“抛出 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();

我想要的只是将命令行输出写入 Report.txt

4

2 回答 2

2

要获得Process输出,您可以使用此处StandardOutput记录的属性。

然后您可以将其写入文件:

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();
于 2012-01-04T18:23:59.757 回答
1

您不能使用>通过 Process 重定向,您必须使用StandardOutput. 另请注意,要使其正常工作StartInfo.RedirectStandardOutput,必须将其设置为 true。

于 2012-01-04T18:24:46.823 回答