Repository navigation
How do I make bat use LF and ^D on Windows, similar to cat on Linux instead of CR LF and ^Z ?
#2884
Replies: 1 comment
|
These are Windows console-runtime conventions, not a bat formatting option. In a native Windows console, Ctrl-Z is the traditional EOF input character, while Ctrl-D is handled as EOF by Unix-like terminal layers (MSYS2/Cygwin/WSL). Text-mode output may also translate LF to CRLF. For Unix cat semantics on Windows, run bat in a Unix-like environment (WSL/MSYS2/Cygwin) and pipe within that environment. Native cmd.exe/PowerShell cannot be made to treat Ctrl-D exactly like a Unix terminal merely through a bat flag. For file input, note that bat preserves the line structure it reads and its normal output path uses Rust stdout; there is no current --line-ending or --eof-key setting. If you need byte-for-byte concatenation, bat is also the wrong layer because syntax highlighting/decorations are text processing—use a binary-mode copy/cat implementation. If patching a native Windows build, the relevant change belongs at process startup: call the MSVCRT _setmode(_fileno(stdin), _O_BINARY) and the same for stdout before Rust I/O wraps the handles. That disables CRLF/Ctrl-Z text translation, but Ctrl-D still depends on the terminal/shell generating EOF rather than a character; Windows console input semantics may still require Ctrl-Z or closing the pipe. Current bat has no _setmode/O_BINARY path in its source and simply wraps io::stdin()/io::stdout() in its controller/output modules: output.rs, controller.rs. |
Uh oh!
There was an error while loading. Please reload this page.
The app description says "A cat(1) clone", so I expected it to behave like
catmore :)GNU coreutils
cat, whether natively on Linux or through emulation such as Cygwin/MSYS2 on Windows, always usesLFcharacters, and when doingcat | hexdump -Cv, it waits for^Dbefore terminating.On Linux,
batbehaves as I expect, usingLFand waiting for^Dwhencating tohexdump. On Windows, however, it usesCRLFand waits for^Zinstead.I doubt there is a setting somewhere to change this, but it would be great if I could be pointed to where to patch my local install of
batto behave more like GNU coreutilscaton Windows.Thanks in advance.
All reactions