{"id":5850,"date":"2018-06-13T13:17:17","date_gmt":"2018-06-13T20:17:17","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/heaths\/?p=3915"},"modified":"2019-02-17T15:29:12","modified_gmt":"2019-02-17T22:29:12","slug":"vswhere-now-supports-utf8-to-override-console-code-page","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/setup\/vswhere-now-supports-utf8-to-override-console-code-page\/","title":{"rendered":"vswhere now supports -utf8 to override console code page"},"content":{"rendered":"<p>A new switch parameter has been introduced to vswhere. You can now pass <code>-utf8<\/code> to force output to write text using UTF-8 to the console, though <a href=\"https:\/\/github.com\/Microsoft\/vswhere\/wiki\/Encoding\">it&#8217;s important to note<\/a> that what the console host does with that encoded can vary greatly. powershell.exe, for example, when redirecting to a file will always encode Unicode regardless of the <code>[Console]::OutputEncoding<\/code> or program output encoding.<\/p>\n<p>The problem is that while Visual Studio 2017 instance data is stored as UTF-8 and the <a href=\"https:\/\/aka.ms\/setup\/configuration\/docs\">query API<\/a> parses this text into Unicode strings in memory, vswhere writes these strings using the console APIs which transcode text based on the active code page or text written to a file or to a pipe is incorrectly transcoded into gibberish&#8230;or at least a bunch of question marks (fallback character). After much discussion, to avoid breaking changes the new switch parameter <code>-utf8<\/code> was added to force text to use UTF-8 expecting that the caller will handle it appropriately as in the following example.<\/p>\n<pre class=\"lang:js decode:true\">const cp = require('child_process');\r\ncp.execFile('vswhere.exe', ['-latest', '-format', 'json', '-utf8'], (err, stdout, stderr) =&gt; {\r\n  var instances = JSON.parse(stdout);\r\n  if (instances.length &gt; 0) {\r\n    \/\/ do something with instances[0].description\r\n  }\r\n});\r\n<\/pre>\n<p><a href=\"https:\/\/github.com\/Microsoft\/vswhere\/wiki\/Installing\">Install vswhere<\/a> and give it a try.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can now force vswhere to output JSON using the UTF-8 encoding.<\/p>\n","protected":false},"author":389,"featured_media":3843,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[20,45,57,60],"class_list":["post-5850","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-installation","tag-visual-studio","tag-vs2017","tag-vswhere"],"acf":[],"blog_post_summary":"<p>You can now force vswhere to output JSON using the UTF-8 encoding.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/5850","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/users\/389"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/comments?post=5850"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/posts\/5850\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media\/3843"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/media?parent=5850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/categories?post=5850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/setup\/wp-json\/wp\/v2\/tags?post=5850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}