Title: CLI: -OutputFormat XML situationally produces broken XML (CLIXML) · Issue #12489 · PowerShell/PowerShell · GitHub
Open Graph Title: CLI: -OutputFormat XML situationally produces broken XML (CLIXML) · Issue #12489 · PowerShell/PowerShell
X Title: CLI: -OutputFormat XML situationally produces broken XML (CLIXML) · Issue #12489 · PowerShell/PowerShell
Description: The CLI's -OutputFormat Xml (-o Xml / -of Xml) parameter produces CLIXML output that can later be read with Import-CliXml, for instance. If a -Command / -c command string / a *.ps1 script file passed to -File writes to multiple streams, ...
Open Graph Description: The CLI's -OutputFormat Xml (-o Xml / -of Xml) parameter produces CLIXML output that can later be read with Import-CliXml, for instance. If a -Command / -c command string / a *.ps1 script file pass...
X Description: The CLI's -OutputFormat Xml (-o Xml / -of Xml) parameter produces CLIXML output that can later be read with Import-CliXml, for instance. If a -Command / -c command string / a *.ps1 script file ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/12489
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CLI: -OutputFormat XML situationally produces broken XML (CLIXML)","articleBody":"The CLI's `-OutputFormat Xml` (`-o Xml` / `-of Xml`) parameter produces CLIXML output that can later be read with `Import-CliXml`, for instance.\r\n\r\nIf a `-Command` / `-c` command string / a `*.ps1` script file passed to `-File` writes to _multiple_ streams, the output XML text is broken in two (possibly related) ways:\r\n\r\n* The single magic `#\u003c CLIXML` comment that is usually on the first line only is _doubled_ (that is, the 2nd line contains the same comment, with only the 3rd line containing the XML).\r\n\r\n* A _2nd_ top-level `\u003cObjs>` root element appears, seemingly covering the non-success streams separately, which results in broken XML as well as a loss of the ordering of output objects.\r\n\r\nAs an aside: it seems that _host_ output is captured as _success_-stream output (`S=\"Output\"`) rather than _information_-stream output (`S=\"information\"`). \r\nIs this by (historical) design, retained for backward compatibility?\r\n\r\n# Steps to reproduce\r\n\r\n```powershell\r\n{ \r\n $ErrorActionPreference = 'Stop'\r\n pwsh -o xml -noprofile -command 'Write-Output output!; Write-Verbose -vb verbose!' | \r\n Write-Output \r\n} | Should -not -Throw\r\n```\r\n\r\n# Expected behavior\r\n\r\nThe test should succeed - no errors should occur.\r\n\r\nNote that the test relies on the fact that PowerShell automatically _deserializes_ CLIXML text when you send it through the pipeline, so that `Write-Output` outputs the deserialized (\"rehydrated\") output objects.\r\n\r\n# Actual behavior\r\n\r\nThe following error occurs:\r\n\r\n```none\r\nExpected no exception to be thrown, but an exception \r\n\"Cannot process the XML from the 'Output' stream of '/.../pwsh': \r\nData at the root level is invalid. Line 1, position 1.\" was\r\nthrown from line:1 char:36 ...\r\n```\r\n\r\nIf you want to examine the actual XML, run the following on Unix:\r\n\r\n```powershell\r\nsh -c 'pwsh -o xml -noprofile -command ''Write-Output output!; Write-Verbose -vb verbose!'' > out.xml'\r\n```\r\n\r\nYou'll see the following content in `out.xml` - note the doubled comment line and the presence of _two_ root elements (broken XML):\r\n\r\n```xml\r\n#\u003c CLIXML\r\n#\u003c CLIXML\r\n\u003cObjs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">\r\n\t\u003cS S=\"Output\">\r\n\t\toutput!\r\n\t\u003c/S>\r\n\u003c/Objs>\r\n\u003cObjs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\">\r\n\t\u003cS S=\"verbose\">\r\n\t\tverbose!\r\n\t\u003c/S>\r\n\u003c/Objs>\r\n```\r\n\r\n\r\n# Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```none\r\nPowerShell Core 7.1.0-preview.2\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2020-04-25T15:33:46Z","url":"https://github.com/PowerShell/PowerShell/issues/12489"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8fa1297e-0898-0a44-4bfa-f0346c851f24 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C844:178F0E:D6DE5C:1350B87:6AFDB13A |
| html-safe-nonce | bd87c5fb16c865433a09d3c42b08ed585e63a33b2295d43d2ee1227f456b61a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODQ0OjE3OEYwRTpENkRFNUM6MTM1MEI4Nzo2QUZEQjEzQSIsInZpc2l0b3JfaWQiOiIzMzA3NDQ5ODQ5OTU1MDcwMjY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b290e28acddfe4042aaeba6748678b8d204c15e726f4e2650b55b62a7d68f2aa |
| hovercard-subject-tag | issue:606794364 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/12489/issue_layout |
| twitter:image | https://opengraph.githubassets.com/32b3df61c2a553b7750021c0f4e06276a62a170882886982b5cb1f12d06519df/PowerShell/PowerShell/issues/12489 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/32b3df61c2a553b7750021c0f4e06276a62a170882886982b5cb1f12d06519df/PowerShell/PowerShell/issues/12489 |
| og:image:alt | The CLI's -OutputFormat Xml (-o Xml / -of Xml) parameter produces CLIXML output that can later be read with Import-CliXml, for instance. If a -Command / -c command string / a *.ps1 script file pass... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3c532f4d069d6fbe9b1837450343d1b9e0619a7d5c4ba0b3b64fd8e0bae67c7e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5396ad00d1c6d19097aee7fc4d00a2eb03432c8f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width