For Programmers: Free Programming Magazines  


Home > Archive > Tcl > July 2004 > Re: Simple expect script has erratic behavior, why?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Simple expect script has erratic behavior, why?
Don Libes

2004-07-23, 3:58 pm

geoff_hazel@yahoo.com (Geoff) writes:

> I have a simple expect script to decrypt a gpg file when passed the
> passphrase on the command line. Yet, when I execute it, sometimes it
> works, sometimes it doesn't. When it works, I get output. When it
> doesn't, it sits there like it's waiting for something, and then exits
> without the desired output. It can fail three times and then work.
> What is going on??? This is my first "expect" script, I'm trying to
> automate a decrypt/encrypt process that I have to run wly. If I
> can get this little script to work, I'm home free.
>
> Here's the script: (expect.test)
>
> #!/usr/bin/expect
> spawn gpg --decrypt crap.gpg
> set password1 [lindex $argv 0]
> expect "*passphrase:"
> send "$password1\r"
> expect eof
>
> When I run it a few times, here's what I get:
> ghazel@dmtl001 [/home/ghazel]
> => ./expect.test crap | grep -v gpg
> Enter passphrase: crap
>
> ghazel@dmtl001 [/home/ghazel]
> => ./expect.test crap | grep -v gpg
> Enter passphrase: crap
>
> ghazel@dmtl001 [/home/ghazel]
> => ./expect.test crap | grep -v gpg
> Enter passphrase: crap
> hi,geoff,you,rock
> hi,zach,you,rock2
>
> If I run the gpg command from the command line, of course it prompts
> for the password, but it runs over and over without any hitch or
> glitch I can detect.
> Replies to geoffreyhazel@yahoo.com or this group.


Your gpg is probably using the broken getpass() described in the
Expect FAQ. The workaround is to add a brief pause ("after 1000")
before sending the password.

Don

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com