我正在尝试将一些cmd输出分成多个字符串,以便稍后用于设置标签。
我使用的代码是:
它会输出类似这样的结果:
我使用的代码是:
ProcessStartInfo diskdrive = new ProcessStartInfo("wmic", " diskdrive get index, model, interfacetype, size");
diskdrive.UseShellExecute = false;
diskdrive.RedirectStandardOutput = true;
diskdrive.CreateNoWindow = true;
var proc = Process.Start(diskdrive);
string s = proc.StandardOutput.ReadToEnd();
它会输出类似这样的结果:
Index InterfaceType Model Size
2 IDE WesternDigital 1000202273280
1 IDE Seagate 500105249280
0 IDE SAMSUNG SSD 830 Series 128034708480
能否将这些内容放在列表或数组中,以便我可以获取例如磁盘2的大小或磁盘0的接口类型。我可以用C#做一些基本的事情,但这超出了我的能力范围 :I
String.Split
吗?或者是使用Regex
? - Kryptosvar allPDisks = Session.QueryInstances(@"root\microsoft\windows\storage", "WQL", "SELECT * FROM MSFT_PhysicalDisk")
MSFT_PhysicalDisk
类提供了您想要获取的所有字段。请参见此链接。 - Chris Dunaway