-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.Category: This is a bug.O-unixOperating system: Unix-likeOperating system: Unix-likeT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
When program tries to canonicalizes /dev/stdin
it should resolve to tty
, pipe
or file
as per configured redirection
I tried this code and attached a pipe to stdin:
use std::fs;
fn main() {
let resolved_path = fs::canonicalize("/dev/stdin").unwrap();
println!("{}", resolved_path.into_os_string().into_string().unwrap());
}
echo " " | cargo run
I expected to see this happen: /dev/stdin
canonicalizes to /proc/14063/fd/pipe:[127582]
Instead, this happened:
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/canon-issue`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:4:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Meta
rustc --version --verbose
:
rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0
Backtrace
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/canon-issue`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:4:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Same thing in Python 3.9.7
import os
print(os.path.realpath("/dev/stdin"))
echo " " | python3 code.py
This is the result
/proc/16616/fd/pipe:[162072]
Metadata
Metadata
Assignees
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.Category: This is a bug.O-unixOperating system: Unix-likeOperating system: Unix-likeT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.