2016-08-24 106 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.