[Tutor] Communicating Between Programs Using Raw Inputs

Steven D'Aprano steve at pearwood.info
Wed Jun 15 00:48:49 CEST 2011


Jacob Bender wrote:
> Dear Python Tutors,
> 
> I was wondering how to break into my one program I made using brute force
> methods. Here's the code:
> 
> password = "Helloworld"
> try= raw_input("What's the password?")
> while try != password:
>      try = raw_input("Incorrect, what's the password?")
> 
> I know how to do it in the command line, but not through another program.
> Generating the random tries for the password isn't the issue, but entering
> the password(s) in between the two programs is an issue because I don't know
> how to make programs communicate through raw inputs.


Normally you would do this by redirecting standard input. What operating 
system are you using? In Linux, you would do something like:


# run script foo.py taking input from the output of bar.py
foo.py < bar.py


at the shell. I don't know how to do it in DOS.

However, I don't know if this will actually work for raw_input. It may 
not. Try it and see.

Perhaps a better way is to have your program accept a user name and 
password on the command line, and only prompt for them if not given. 
Then you can say:

foo.py --user=fred --password="y8Mr3 at hzi"


Hope this helps,



-- 
Steven



More information about the Tutor mailing list