From my man page on passwd... . Yours might not accept input from a script, depending on the system.
Code:
PASSWD(1) User utilities PASSWD(1)
NAME
passwd - update a user’s authentication tokens(s)
...
--stdin
This option is used to indicate that passwd should read the new password
from standard input, which can be a pipe.