【发布时间】:2021-06-13 03:45:10
【问题描述】:
我可以用下面的代码得到这个过程的输出
var p = new Process
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true,
FileName = "cmd",
Arguments = "list id"
}
};
p.Start();
var _Data = await p.StandardOutput.ReadToEndAsync();
await p.WaitForExitAsync();
File.WriteAllText("asd.txt", _Data);
在输出中我有这样的信息
Name Id Version
----------------------------
WinRAR RARLab.WinRAR 6.01.0
问题是如何获取name、id、version这3个字段?
【问题讨论】:
-
你必须parse the string。除非您只要求这个特定示例,否则没有通用方法可以做到这一点,因为两个不同进程的输出可能非常不同
-
这能回答你的问题吗? Read fixed width record from text file
标签: c#