I know the security risks, but I am performing this experiment/exercise on an old, seldom used *nix machine I have laying around the house. So doing this exercise will not bring any security risk to my machine. Having said that, please do not post any comments regarding security.

I also know I can change sudoers to disable password prompts, but I am not interested in that.

I have found a command:

echo "password" | sudo -S su

but which works very oddly. I type it in, and the domain stays the same; I don't change into root. Is there something else I'm missing or is there a better way to do this?

Things I've done:

added a \n to the end of the password: password doesn't verify correctly.

I have the nagging feeling that you are trying to run an interactive shell form su (and friends) while doing i/o redirection. I don't think that will work namely echo passwd| will give you an eof (end of file) after the password. I think you are going to need something like expect or a dial script utility. expect has a pass-through mode which can be invoked at the end of the script. this is not needed if your command is not interactive like xterm (which although fully interactive does not need standard input. also watch out for some password being read from standard error which makes things interesting to say the least. (they do that so that i/o redirection is less likely to interfere with your password prompt)