That doesn't work because passwd whats to have a real terminal in order to disable the typed characters' visibility.
i) get some type of terminal "around"
ii) code a program using e.g. PAM routines to change password
iii) write a script that directly alters the location where the password is stored (e.g. /etc/shadow , LDAP, ...)