For SSH-connections I wrote a "wrapper" (to do automatic IP-address lookups etc.) and in the background it is using Plink.exe (the CLI version of Putty). This was working very well for a while now. Unfortunately with the latest version (0.83) I just downloaded something changed. At first I though my wrapper needed to be adjusted, but then I realized it might not have to do anything with my wrapper at all. It seems the latest Plink.exe version does not use STDOUT or STDERR for all output.
Here are the things I tested: Specifically if the host key of a server is not saved yet and it shows "host key is not cached ... The server's rsa2 key fingerprint is: ...If you trust this host, enter "y" ...". This text-block is apparently sent directly to the Console (and not STDOUT or STDERR) with the latest 0.83 version.
I did the following redirection test with 2 different Plink versions (to a host where the host-key is not stored yet):
plink.exe -pw "password" username@10.1.24.1 > C:\DATA\STDOUT.txt 2> C:\DATA\STDERR.txt
When I do this with Plink version 0.80 it takes the command and nothing else shows up in the CLI-window (like it should be as STDOUT and STDERR are being redirected into the 2 files). The same command using Plink version 0.83 I get the following output in the CLI-window:
The host key is not cached for this server:
10.1.24.1 (port 22)
You have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 SHA256:OurTXI1/ilANVeettt4fgeQWD7INzksLaRzcemYevLk
If you trust this host, enter "y" to add the key to Plink's
cache and carry on connecting.
If you want to carry on connecting just once, without adding
the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n, Return cancels connection, i for more info)
Why is this not sent out via STDOUT or STDERR? I read online this might happen if the program is writing directly to CON (Console), but I am not sure ... I never had this type of issue. Obviously my wrapper cannot act on these messages as it does not "see" them.
Is there a way to convince Plink to use the standard handles? At this point I am scratching my head not sure what to do next.
This link (talking about C#, but also has a redirect "problem"). One answer suggests that it might be difficult to do ... Capture ALL (stdout, stderr AND CON) output of cmd executing plink with C# (std out+err ok, CON not working)
Thanks for any help/ suggestion!
It's due to this change in PuTTY 0.82:
Send Windows console tools' prompts directly to the console
A possible workaround is mentioned there:
If this change causes a problem for you, you can get the old behaviour by adding the option
-legacy-stdio-prompts
to the command line.
The -legacy-stdio-prompts
switch is documented here:
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-legacy-stdio-prompts
Though a better solution is to pass an expected hostkey fingerpring using -hostkey
switch to avoid getting the prompt in the first place:
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-hostkey