Piping to a python script

Hello,

I have a python script (not created by me), let's call it myscript, which I call with several parameters. If I don't provide the --password parameter, the script will ask the user to input the password.
So I run the script like this:

/wherever/myscript --username=whoever /some/other/path/parameter

That makes it ask for a password and wait for user input. If I enter the wrong password an error message will be displayed.
I want to pipe to this script some preset text to enter as the password, so that I can mimic entering an invalid password by hand.

echo 'wrongpassword' | /wherever/myscript --username=whoever /some/other/path/parameter

This unfortunately doesn't generate the same behaviour, as if it would be manually entered.
Can I simulate this behaviour with pipes/redirecting output? Why doesn't it work? I expect that the 'wrongpassword' text will be entered when the script asks for the password, but it seems I'm wrong.

Thanks!

This is exactly the problem that people have when trying to automate ssh passwords. Instead of reading a password from stdin, the programs open the terminal directly. So by using a pipe, you're attaching a stream to stdin which is sent to myscript, but myscript does not read the password from stdin!

There is a TCL scripted program, called expect that simulates a terminal. Though putting passwords into files is not a very smart thing to do. I cannot provide assistance with creating an expect script though the man page does provide some examples.

There is a reason passwords are not read from standard input, incidentally. Most sane login systems are designed to stop what you're doing, because it's a really, really bad idea for a huge number of reasons. "Interactive password authentication" means "Password typed by a human being in realtime authentication" and no artificial substitutes for humans are acceptable.

If you want something noninteractive, look into mechanisms like SSH keys.

Thank you for the insights! Didn't think of that...