cargo-graph icon indicating copy to clipboard operation
cargo-graph copied to clipboard

cargo-graph generates incompatible dot files in powershell

Open Trolldemorted opened this issue 6 years ago • 3 comments

When starting cargo graph in windows' cmd shell, the output file is ASCII text. When you start it in windows' powershell, the output file is Little-endian UTF-16 Unicode text, with CRLF, CR line terminators and a byte order mark.

dot fails to produce pngs from such a file:

PS C:\Users\Benni\repositories\parity> dot -Tpng > rainbow-graph.png cargo-count-ps.dot
Error: cargo-count-ps.dot: syntax error in line 1 near ' ■d'

Trolldemorted avatar Jan 08 '18 21:01 Trolldemorted

File is opened here:

https://github.com/kbknapp/cargo-graph/blob/d895af1b7840c7ae8eddaf4e990bfa594c22ba01/src/main.rs#L332-L334

And written to here:

https://github.com/kbknapp/cargo-graph/blob/d895af1b7840c7ae8eddaf4e990bfa594c22ba01/src/graph.rs#L222

I'm surprised this would happen. I don't see a reason for it?

remram44 avatar Jan 08 '18 21:01 remram44

The example and thus I are piping the content into a file, so cfg.dot_file is None, and stdout's encoding depends on the shell you use I presume?

Edit: Even if I write only a single letter this way, the BOM and encoding is that way, so I guess powershell uses utf16 (or something similar) and stdout adheres to that.

Trolldemorted avatar Jan 08 '18 22:01 Trolldemorted

I really assumed write!() always outputted UTF-8. I don't know where this translation could be happening.

remram44 avatar Jan 09 '18 04:01 remram44