2016-08-24 134 views
0

我的情景:WMIC命令追加结果

我用来收集软件细节的WMIC命令。

WMIC产品获取描述,名称,版本/格式:CSV> /softwarelist.csv

这工作得很好。

但我需要将结果追加到同一个输出file.ie,如果我在另一个系统上运行该脚本,它必须将输出写入同一个softwarelist.csv文件。

我试过使用APPEND命令,但它给出了访问被拒绝的错误。

WMIC /APPEND:"\softwarelist.csv”产品得到描述,名称,版本/格式:CSV

任何帮助将不胜感激..

回答

1

Redirection

command > filename  Redirect command output to a file 
command >> filename  APPEND into a file 

您可以使用>>,请参阅下一个语法:

wmic product get description,name,version /format:csv >>/softwarelist.csv 

阅读wmic/APPEND /?

APPEND - Specifies the mode for output redirection. 
USAGE: 

/APPEND:<outputspec> 
NOTE: <outputspec> ::= (STDOUT | CLIPBOARD | <filename>) 
     STDOUT  - Output will be redirected to the STDOUT. 
     CLIPBOARD - Output will be copied on to CLIPBOARD. 
     <filename> - Output will be appended to the specified file. 

NOTE: Enclose the switch value in double quotes, if the value contains special 
     characters like '-' or '/'. 

wmic /APPEND虽然看起来<filename>不接受相对路径,看下例子应该正常工作。二者必选其一裸文件名或完整的文件路径:

==> dir /B "\softwarelist.csv" 
File Not Found 

==> >NUL wmic /APPEND:"\softwarelist.csv" product get description,name,version /format:csv 
Invalid file name. 

==> >NUL wmic /APPEND:"D:\softwarelist.csv" product get description,name,version /format:csv 

==> dir "\softwarelist.csv" | findstr "softwarelist.csv$" 
27.08.2016 19:47   48 644 softwarelist.csv 

注意dir /B "\softwarelist.csv"确保在上面的代码片断作品后wmic /APPEND

此外,系统驱动器的根目录被保护(因为Vista的次?),看到访问被拒绝消息:

==> pushd c: 

==> wmic product get description,name,version /format:csv >/softwarelist.csv 
Access is denied.