> 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.
~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
We can check for FIFOs via https://doc.rust-lang.org/stable/std/os/unix/fs/trait.FileTypeExt.html#tymethod.is_fifo
Very cool.
Thank you for help. Your observation ("maybe the file is being read before we can interact with it") was spot-on!