[Tutor] Re: Question about stdin/stdout

Lee Harr missive at hotmail.com
Thu May 27 18:04:49 EDT 2004

>I realise that "Activate pin 1" won't work, but I can sort that out. I
>just want to know about stdin/stdout.
>What I want to do is get the program to read a screen display (or I can
>get Linux to save this display to a file using the "tail -f" command) or
>file, and when it recognises the line with the call sign "UA6ADV" (or
>one of the other call signs) it will then send a cmd to the parallel
>port, ttyS0, to make one of the pins go high.

You may want to look here:

In answer to your questions about stdin/stdout...

Essentially, they are just files like any other files...

>>>import sys
<open file '<stdin>', mode 'r' at 0x8132020>
<open file '<stdout>', mode 'w' at 0x8132060>
>>>f = file('atempfile', 'w')
<open file 'atempfile', mode 'w' at 0x815fa60>

The magic thing is that print is hooked up automatically to
stdout, but you can rearrange that if you really want to...

>>>f.write('some test text')
>>>f.write('some test text with newline\n')
>>>print 'testing print'
testing print
>>>sys.stdout = f
>>>print 'testing print'
>>>print 'testing print'
>>>print 'testing print'
>>>[...here I exited the interpreter]
17:56 >more atempfile
some test textsome test text with newline
testing print
testing print
testing print

Most likely though, you would want to just open a new file and write
to it, rather than redirecting stdout.

MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 

More information about the Tutor mailing list