how to pass passcode to a command?

Hi group,

I'm writing a bash script and part of the code is connection between to
machine so I need to have password to pass to the command.

Now, how can I redirect the password question? is it possible to
redirect it to /dev/null and somehow write a code to ask for password
in a managed way and pass it to the command. Let's say the command is

scp localmachine root@remotemachine:/tmp

or maybe it won't be safe?!! any suggestions?