如何在wmic输出中使用分隔符分隔列?

我想用某种格式获取Windows Hotfix列表,其输出可以用一些分隔符分隔。 到目前为止,我发现了一个wmic命令,它给了我一个期望的输出,但问题是\s分隔符不会在这里工作。 有没有办法,我可以放置一些,或者其他字符,我可以稍后在java程序中使用获取单个列?

命令

 wmic qfe get caption,csname,description,hotfixid,installedby,installedon 

产量

 Caption CSName Description HotFixID InstalledBy InstalledOn http://go.microsoft.com/fwlink/?LinkId=161784 Abhishek Update KB971033 NT AUTHORITY\SYSTEM 3/15/2012 http://support.microsoft.com/?kbid=2032276 Abhishek Security Update KB2032276 NT AUTHORITY\SYSTEM 3/15/2012 .. . 

更新

我在尝试

 for /f "tokens=1,2,3,4,5,6,7,8,9,10,11" %g in ('wmic qfe get caption,csname,description,fixcomments,hotfixid,installdate,installedby,installedon,name,servicepackineffect,status') do @echo %g,%h,%i,%j,%k,%l,%m,%n,%o,%p 

但它给了我无效的GETexpression式

 C:\Users\Abhishek\Desktop>for /f "tokens=1,2,3,4,5,6,7,8,9,10,11" %g in ('wmic qfe get caption,csname,description,fixcomments,hotfixid,installdate,installedby,installedon,name,servicepackineffect,status') do @echo %g,%h,%i,%j,%k,%l,%m,%n,%o,%p Invalid GET Expression. 

这里有什么问题? 这可能为我解决这个问题。

更新

我甚至尝试了下面的命令,但是这也不能解决空间问题

命令

 for /f "tokens=1,2,3,4,5,6,7,8,9,10,11" %g in ('wmic qfe list') do @echo %g,%h,%i,%j,%k,%l,%m,%n,%o,%p 

产量

 Caption,CSName,Description,FixComments,HotFixID,InstallDate,InstalledBy,InstalledOn,Name,ServicePackInEffect http://go.microsoft.com/fwlink/?LinkId=161784,Abhishek,Update,KB971033,NT,AUTHOR,,Y\SYSTEM,3/15/2012, http://support.microsoft.com/?kbid=2281679,Abhishek,Security,Update,KB2281679,NT,AUTHORITY\SYSTEM,3/15/2012, http://support.microsoft.com/?kbid=2284742,Abhishek,Update,KB2284742,NT,AUTHORIT,,SYSTEM,3/15/2012, http://support.microsoft.com/?kbid=2286198,Abhishek,Security,Update,KB2286198,NT,AUTHORITY\SYSTEM,3/15/2012, 

正如我在wmic的结果中看到的那样,列至少2个空格隔开。

 Caption CSName Description HotFixID InstalledBy InstalledOn http://go.microsoft.com/fwlink/?LinkId=161784 Abhishek Update KB971033 NT AUTHORITY\SYSTEM 3/15/2012 http://support.microsoft.com/?kbid=2032276 Abhishek Security Update KB2032276 NT AUTHORITY\SYSTEM 3/15/2012 

所以这可以通过使用\s{2,}正则表达式拆分来在Java中轻松解析:

 String result = "..."; for (String line : result.split("\n")) { System.out.println("-> " + line); for (String column : line.split("\\s{2,}")) { System.out.println(" => [" + column.trim() + "]"); } } 

输出:

 -> Caption CSName Description HotFixID InstalledBy InstalledOn => [Caption] => [CSName] => [Description] => [HotFixID] => [InstalledBy] => [InstalledOn] -> http://go.microsoft.com/fwlink/?LinkId=161784 Abhishek Update KB971033 NT AUTHORITY\SYSTEM 3/15/2012 => [http://go.microsoft.com/fwlink/?LinkId=161784] => [Abhishek] => [Update] => [KB971033] => [NT AUTHORITY\SYSTEM] => [3/15/2012] -> http://support.microsoft.com/?kbid=2032276 Abhishek Security Update KB2032276 NT AUTHORITY\SYSTEM 3/15/2012 => [http://support.microsoft.com/?kbid=2032276] => [Abhishek] => [Security Update] => [KB2032276] => [NT AUTHORITY\SYSTEM] => [3/15/2012] 

对于批处理方面,我无法帮助你,因为我对它一无所知:-)

编辑:显然有一个开关/format:csvwmic ,应该生成一个CSV,你也可以轻松地在Java中解析。 我不能让它在我的机器上工作,但值得注意。

如果您使用Powershell,请按照以下博客条目进行操作: http : //blogs.technet.com/b/manny/archive/2012/02/04/perform-a-full-export-and-import-of-wmi-filters -with-powershell.aspx