I am pretty sure that one CANNOT
do passwd's via a shell - that is why you get this error:
standard in must be a tty
A passwd must typed from the keyboard -it's one of the basic security features of any linux/unix.
I could be wrong (it wouldn't be the first time
I guess that you will have to resign yourself to typing in the passwd at the prompt.