Skip to content

Guidance on output redirection for Windows #31

@DanielRosenwasser

Description

@DanielRosenwasser

If I try running the trace analyzer with npx analyze-trace --color false > foo.txt, then foo.txt gets something like the following output.

Hot Spots
Γö£ΓöÇ Check file c:\users\Daniel\scratch\ant-design-icons\packages\icons-react\node_modules\typescript\lib\lib.dom.d.ts (816ms)
Γö£ΓöÇ Check file c:\users\Daniel\scratch\ant-design-icons\packages\icons-react\node_modules\@types\babel__traverse\index.d.ts (511ms)
ΓööΓöÇ Check file c:\users\Daniel\scratch\ant-design-icons\packages\icons-react\node_modules\@types\react\index.d.ts (507ms)

instead of the expected box drawing characters

Hot Spots
├─ Check file c:\users\Daniel\scratch\ant-design-icons\packages\icons-react\node_modules\typescript\lib\lib.dom.d.ts (816ms)
├─ Check file c:\users\Daniel\scratch\ant-design-icons\packages\icons-react\node_modules\@types\babel__traverse\index.d.ts (511ms)
└─ Check file c:\users\Daniel\scratch\ant-design-icons\packages\icons-react\node_modules\@types\react\index.d.ts (507ms)

This is apparently because Node.js outputs to UTF8, and PowerShell's redirection functionality (at least the version I'm using, 5.1) thinks it's receiving UTF16. The fix is to set

[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions