From 66e8c1600ec8c18cbcdce56647b63488599d1b95 Mon Sep 17 00:00:00 2001 From: Hraban Luyat Date: Sat, 15 Apr 2017 18:17:53 +0100 Subject: [PATCH] Print password prompts to stderr This makes rclone with encrypted config better suited for use in pipelines. E.g.: $ rclone lsl mydrive:Some/Dir | sort -k 4 If the password prompt ("Enter configuration password") is printed to stdout, it will be swallowed by sort. By printing it to stderr, you still see the prompt, without sacrificing compatibility with the unix pipeline. --- fs/config.go | 8 ++++---- fs/config_read_password.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/config.go b/fs/config.go index f3e684962..4caa69482 100644 --- a/fs/config.go +++ b/fs/config.go @@ -516,15 +516,15 @@ func checkPassword(password string) (string, error) { // GetPassword asks the user for a password with the prompt given. func GetPassword(prompt string) string { - fmt.Println(prompt) + fmt.Fprintln(os.Stderr, prompt) for { - fmt.Print("password:") + fmt.Fprint(os.Stderr, "password:") password := ReadPassword() password, err := checkPassword(password) if err == nil { return password } - fmt.Printf("Bad password: %v\n", err) + fmt.Fprintf(os.Stderr, "Bad password: %v\n", err) } } @@ -553,7 +553,7 @@ func getConfigPassword(q string) { if err == nil { return } - fmt.Println("Error:", err) + fmt.Fprintln(os.Stderr, "Error:", err) } } diff --git a/fs/config_read_password.go b/fs/config_read_password.go index 19c60cd98..08892cfb3 100644 --- a/fs/config_read_password.go +++ b/fs/config_read_password.go @@ -18,7 +18,7 @@ import ( // ReadPassword reads a password without echoing it to the terminal. func ReadPassword() string { line, err := terminal.ReadPassword(int(os.Stdin.Fd())) - fmt.Println("") + fmt.Fprintln(os.Stderr) if err != nil { log.Fatalf("Failed to read password: %v", err) }