Skip to content

Password: Returns Err when used in conjunction with input via redirect or pipe #296

Open
@sorairolake

Description

@sorairolake

The following code reads bytes from stdin and then enters the password:

use std::io::{self, Read};

use dialoguer::{theme::ColorfulTheme, Password};

fn main() {
    let mut buf = Vec::new();
    io::stdin().read_to_end(&mut buf).unwrap();

    let passphrase = Password::with_theme(&ColorfulTheme::default())
        .with_prompt("Enter passphrase")
        .with_confirmation("Confirm passphrase", "Passphrases mismatch, try again")
        .interact()
        .unwrap();

    println!("{buf:?}");
    println!("{passphrase}");
}

This works well when the user enters bytes directly. However, when inputting bytes via redirect or pipe (e.g. echo "foo" | cmd or cmd < infile), this returns Bad file descriptor when entering the password.

called `Result::unwrap()` on an `Err` value: IO(Os { code: 9, kind: Uncategorized, message: "Bad file descriptor" })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions