Reputation: 1
My scenario:
I have a wmic
command used to collect software details.
wmic product get description,name,version /format:csv > <sharepath>/softwarelist.csv
This works fine.
But I need the results to be appended on the same output file, i.e. if I run the script on another system, it has to write the output to the same softwarelist.csv file.
I have tried using the APPEND
command, but it gives access denied error.
wmic /APPEND:"<shared folder>\softwarelist.csv" product get description,name,version /format:csv
Any help will be appreciated..
Upvotes: 0
Views: 9433
Reputation: 30133
Read Redirection:
command > filename Redirect command output to a file command >> filename APPEND into a file
You could use >>
, see next syntax:
wmic product get description,name,version /format:csv >>/softwarelist.csv
Read 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
should work as well although it appears that <filename>
does not accept relative paths, see next example. Use either bare file name or fully qualified file path:
==> 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
Note that dir /B "\softwarelist.csv"
ensures that the later wmic /APPEND
in above code snippet works.
Moreover, root directory of system drive is protected (since Vista times?), see Access is denied message:
==> pushd c:
==> wmic product get description,name,version /format:csv >/softwarelist.csv
Access is denied.
Upvotes: 2