[Tutor] Communicating Between Programs Using Raw Inputs

Alan Gauld alan.gauld at btinternet.com
Wed Jun 15 01:36:13 CEST 2011


"Jacob Bender" <benderjacob44 at gmail.com> wrote

> 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.

You need to search for stdin and stdout. Try wikipedia.
Then google python stdin

By linking stdout of one program to stdin of another you can pass
data between them. This is one of the things that makes Unix
such an insanely great programmers OS, its commands are
explicitly designed to do this. But you can make it work with
any command that prints to stdout and reads from stdin.

If you read the "Talking to the User" topic in my tutorial you
will see a sidebar/box that discusses this and gives an example
of reading from a file. You need to take that one step further and
read from a process. In Unix the easiest way you can do that is
to surround the command with backtick marks:

python reader.py < `python writer.py`

notice the *back* quote marks.

There are other ways of doing it inside Python, seee my
"Using the OS" topic for those. But backtics and stdin should
do what you need.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list