Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zpty woes



Jaime Vargas wrote:
> In the script attached, when trying to follwing line always fails.
> 
>      zpty -r scppty line "*:" || echo "no password asked" && exit
> 
> It appears that the "password" string from the ssh session is discarded
> by the psuedo terminal.
> 
> Is there a way to fix this? or Am I missing something?

Yes and yes, but it's annoying and I spent a few minutes rediscovering
the arcana.  zpty attempts to read in whole lines, while the password
prompt isn't a whole line.  I came across this myself and looked at the
code a while ago and it seemed unnecessarily obscure.  However, I worked
around it and don't have time to make it work sensibly in all the
possible cases, so I'm not touching it.  (If anyone's interested it's in
ptyread() in Src/Modules/zpty.c and could definitely do with someone
taking it over; it's pretty much self-contained.)

To work around this, you need to use non-blocking mode, i.e. start with
"zpty -b scppty ...".  I think (although the code is obscure) that with
your "*:" pattern this will work, i.e. although it doesn't block it will
carry on reading until it gets the password input.  If not, you would
need to delay (the zsh/zselect module allows you to do this in 100ths of
a second) and retry.  (Waiting for a pattern with noblocking is
effectively a busy wait so even this isn't ideal---you can add the -t
option to the -r command line to test first, but then it *won't* wait
if there's no input and you do have to delay in your script.)

Anyway, it now seems to work for me (though if there were an occasional
race I might have missed it).

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author