Hemachandran Namachivayam wrote: > Hi Hugh, > > Thanks for the suggestion. My requirement would be *not* to use any other > packages (such as expect etc..). Is there a way to do so with just shell > comamds ?
The reason that getpassphrase() works in expect is that expect makes a new pseudo-terminal and then runs the getpassphrase app with the app thinking its controlling terminal is the expect-controlled pty. Expect can then inject input into this new pseudo-terminal, while the app being controlled thinks it's getting its input directly from a terminal. You need to do something like this because getpass() internally calls fopen("/dev/tty", "r+F") and also does a bunch of terminal ioctls on this. So you do need to have a tty. What this means to your followup question is that you don't have to use expect, but probably only if you do one of the following: 1. Perl has an Expect.pm module. So you could use this, if you're willing to install it or bundle this in Solaris. Note though that this seems to be not installed by default, and since expect is really just a tcl script, you're replacing one scripting language with another. 2. You could write your own wrapper binary (you probably can't do this in shell code) that creates a pty like expect. This is the "lots of work" option, especiallly since expect is a well-respected package. 3. Write a LD_PRELOAD wrapper that overrides getpassphrase(). This is a hack though and is not encouraged. #2 in particular may be more work than you want, compared to just using expect. Hugh.