microsoft / update-server-server-sync

Sample implementation of the "Windows Update Services: Server-Server" protocol.
MIT License
48 stars 19 forks source link

Unable to store query results in a local file #9

Closed xiangkangjw closed 2 years ago

xiangkangjw commented 2 years ago

I have followed the instructions and was able to query results and print in console, however, I wasn't able to store it in a local file, could you please advise?

When I run the command .\upsync.exe query --store-path .\store --package-type microsoft-update, it works just fine. However, when I try to pipe it to a result file (.\upsync.exe query --store-path .\store --package-type microsoft-update *> results.txt), it has an error. I have attached the error message in a file attached in this email.

I later found out this might be because the console library is being used in the MicrosoftUpdateMetadata.cs file. I tried to run it in a separate cmd inside Powershell but only generated partial results, I also attached the result in this email.

Do you know how to store the result in a local file? Thank you so much.

error-message.txt partial-result.txt

Almost-Done commented 2 years ago

Thank you @xiangkangjw for reporting this issue!

When pretty printing update metadata, the code is directly manipulating the console cursor location in order to indent text. This manipulation is not supported when redirecting to a text file.

The issue is fixed by printing the required number of white spaces in order to maintain indenting. This is compatible with console redirection and should fix this issue.

See commit 542f6c4f1e8a6c40da4f5fdfe99f0c181ae922ac

However, further processing of the pretty printed output might be unwieldy. I also added a "--json-out-path " command line switch that will output the result of the query to a specified JSON file. The JSON file will contain an array, each object in the array is package (update) metadata serialized to JSON.

See commit d124d142f05c2a6590efd1e13d893b95e18d08c5

Please let me know if you still encounter issues.