develooper Front page | perl.beginners | Postings from April 2003

RE: passing a password

Thread Previous | Thread Next
From:
Bob Showalter
Date:
April 30, 2003 05:52
Subject:
RE: passing a password
Message ID:
2E4528861499D41199D200A0C9B15BC001D7E866@FRISTX
Jeff Hardy wrote:
> I have a quick question.  I am writing a script that calls a little C
> program (in this case, the cups utility cupsaddsmb).  I call the
> program with no problem using a system call like so:
> 
> system("/usr/sbin/cupsaddsmb -U admin $queue");
> 
> $queue is the printer i want to add.  The problem is that the
> cupsaddsmb utility prompts for a password.  How can I send that
> password along to the program?  I tried making my system call with a
> pipe to an echo password like this: 
> 
> system("/usr/sbin/cupsaddsmb -U admin $queue | echo password");

This is backwards. If cupsaddsmb reads the password from stdin, you can pass
it as:

   system("echo password | /usr/sbin/cupsaddsmb -U admin $queue");

However, it probably reads the password from /dev/tty, so the above
technique won't work. If cupsaddsmb doesn't support an alternate way of
providing the password, you need to use something like the Expect module,
which lets you control the program through a pseudo tty.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About