sudo
-S, --stdin
Write the prompt to the standard error and read the password from the standard input instead of using the terminal device. The password must befollowed by a newline character.
echo <mypasswd> | sudo -S <cmdline>
e.g.: echo 1234567 | sudo -S service tftpd-hpa restart