Bat: Process substitution does not work with bat

Created on 7 May 2018  ยท  13Comments  ยท  Source: sharkdp/bat

> cat <(echo hello)
hello

> bat <(echo hello)
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
       โ”‚ File: /proc/self/fd/11
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

The /proc/self/fd/11 filename is expected, but somehow we fail to read the file contents.

bug help wanted

All 13 comments

~On Mac OS X (and possibly other platforms), using a pipe (|) will output nothing at all.~

Edit:
My bad. I can also confirm that this bug (named pipes) happens on Mac OS X High Sierra.

use strace on bat to see whether it has read input from stdin

On Mac OS X (and possibly other platforms), using a pipe will output nothing at all.

echo "Hello world" | bat

Reading from stdin is not supported in the latest release (only in master), see #2.

This bug is not related to reading from stdin. This is about reading from named pipes.

I did some debugging, and the issue is related to the BufReader It's failing to read anything for some reason, but you can read it fine from the regular File handle

Hm, I can not reproduce the bug with this small example:

use std::env;
use std::fs::File;
use std::io::{BufReader, BufRead};

fn main() {
    let filename = env::args().nth(1).unwrap();
    println!("Reading from {}", filename);

    let file = File::open(filename).unwrap();
    let mut reader = BufReader::new(file);

    let mut contents = String::new();
    reader.read_line(&mut contents).unwrap();
    println!("First line: {}", contents);
}
โ–ถ cargo run -- <(echo hello)
   Compiling test_process_substitution v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 0.55 secs
     Running `target/debug/test_process_substitution /proc/self/fd/11`
Reading from /proc/self/fd/11
First line: hello

(edited)

You're right. Something else is going on. If you try it with a longer file like src/main.rs in bat, it only prints part of the file. A huge chunk of it is lost. With process substitution, you can only read the file once, so maybe the file is being read before we can interact with it. I've checked most of the other steps, and my only other hunch is clap?

Wow, interesting. Thanks for investigating.

I think I know where this comes from. syntect is probably reading parts of the file when trying to infer the language.

This works:

bat --language md <(cat README.md)

Nice! I completely skipped that. How would this be handled though

Very cool.

Thank you for help. Your observation ("maybe the file is being read before we can interact with it") was spot-on!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

niedzielski picture niedzielski  ยท  3Comments

yum-feng picture yum-feng  ยท  3Comments

mjlbach picture mjlbach  ยท  3Comments

samuelcolvin picture samuelcolvin  ยท  3Comments

jkaan picture jkaan  ยท  3Comments