Pearte has asked for the wisdom of the Perl Monks concerning the following question:

People, I want to call functions like passwd and smbpasswd from within a perl script. I have tried using system(), fork() and exec(), as well as puting the line in ``. In all cases, there seems to be a background process running, but I do not see the prompts. The problem is not that the process isn't running but that I cannot see the function's prompts for the new passwords. Thoughts? p
  • Comment on Calling interactive programs from with a script

Replies are listed 'Best First'.
Re: Calling interactive programs from with a script
by mce (Curate) on Aug 28, 2002 at 09:56 UTC
    Hi,
    First, look here for formatting your post.
    Second, this is really a unix question, not a perl one, since this is the way passwd works.
    Please look at Expect for some clues how to solve your problem.

    Yours,
    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium

      Second, this is really a unix question, not a perl one, since this is the way passwd works.
      I disagree. He's not having problems with passwd per se, he's having problems accessing it through perl. There is a difference.

      As for the original question, I think that part of the problem can have some light shed on it by the answer to the question "where do stdout and stderr go when you do a system call?" . Also, passwd expects a tty to be communicating with it, and has provisions to prevent things like scripts interfacing with it. Fortunately for you, Expect.pm is around. Expect simulates a tty, allowing you to script an interface to things like passwd.

      thor