Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sorairolake opened this issue Dec 1, 2023 · 2 comments

Comments

@sorairolake
Copy link

sorairolake commented Dec 1, 2023

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" })
@sorairolake sorairolake changed the title Password: Returns Err when used in conjunction with input via redirect or pipe Password: Returns Err when used in conjunction with input via redirect or pipe Dec 1, 2023
@hepptho
Copy link

hepptho commented Jan 1, 2024

Not sure if it's related, but I have a similar problem with FuzzySelect.

Example:

use dialoguer::FuzzySelect;

fn main() {
    let options = ["abc", "def", "ghi"];
    let index = FuzzySelect::new()
        .with_prompt("Select")
        .items(&options)
        .interact().unwrap();
    println!("selected: {}", options[index]);
}

This works fine when stdin is empty, but when piping anything into the command it will crash:

thread 'main' panicked at src\main.rs:8:21:
called `Result::unwrap()` on an `Err` value: IO(Os { code: 1, kind: Uncategorized, message: "Incorrect function." })

I am on windows, msvc toolchain, rust 1.75.0.

@mike-lloyd03
Copy link

I'm having the same issue running on Linux. Piping from another process raises an error IO error: Bad file descriptor (os error 9).

Anyone figured out a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants