conradkleinespel / rpassword

Cross platform Rust library to read a password in the terminal (Linux, BSD, OSX, Windows, WASM).
Apache License 2.0
243 stars 38 forks source link

read_password reading over newline #36

Closed u05rav closed 5 years ago

u05rav commented 5 years ago

I have an issue where I want to have a bash script that reads multiple lines from stdin and one of those lines should be consumed as a password in my rust code but the subsequent lines are read by the script. The problem is that read_password is swallowing all the lines. Here is an example

extern crate isatty;
extern crate rpassword;

fn main() {
    let user_input = rpassword::read_password();
    println!("{}", user_input.unwrap());
}

I'm calling it from a bash script like this

#!/bin/bash 
./target/debug/password_read
read SECOND
echo $SECOND

and finally I call the bash script like this

./test.sh < <( echo -e "first
second")

I expect to see both first and second echoed back to me but what I actually see is

$ ./test.sh < <( echo -e "first
second")
first

The rust code is swallowing the second line and it's not available to be read by my script.

conradkleinespel commented 5 years ago

@u05rav Hey ! Thanks for reporting this. Would you be open to working on a fix for this ?

conradkleinespel commented 5 years ago

@u05rav Given that this issue has been inactive for a while, I'm going to close it. If someone is able to work on a fix for this, feel free to comment and we'll open it up again.