Skip to content

Commit 49040e4

Browse files
committed
Use Console.ReadLine when stdin redirected
1 parent afa09b0 commit 49040e4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Sshfs/SSHFS.CLI/Program.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void Start(Options options)
100100
else if (options.Password)
101101
{
102102
Console.WriteLine("No SSH key file selected, using password auth instead.");
103-
var pass = ReadLine.ReadPassword("Please enter password: ");
103+
var pass = ReadPassword("Please enter password: ");
104104

105105
auths.AddRange(new(string, ConnectionInfo)[]
106106
{
@@ -122,12 +122,21 @@ static PrivateKeyConnectionInfo PrivateKeyConnectionInfo(Options options)
122122
{
123123
var pkFiles = options.Keys.Select(k =>
124124
options.Password
125-
? new PrivateKeyFile(k, ReadLine.ReadPassword($"Enter passphrase for {k}: "))
125+
? new PrivateKeyFile(k, ReadPassword($"Enter passphrase for {k}: "))
126126
: new PrivateKeyFile(k));
127127

128128
return new PrivateKeyConnectionInfo(options.Host, options.Port, options.Username, pkFiles.ToArray());
129129
}
130130

131+
static string ReadPassword(string prompt)
132+
{
133+
if (!Console.IsInputRedirected)
134+
return ReadLine.ReadPassword(prompt);
135+
136+
Console.WriteLine(prompt);
137+
return Console.ReadLine();
138+
}
139+
131140
static KeyboardInteractiveConnectionInfo KeyboardInteractiveConnectionInfo(Options options, string pass)
132141
{
133142
var auth = new KeyboardInteractiveConnectionInfo(options.Host, options.Port, options.Username);

0 commit comments

Comments
 (0)