popen problem
Gandalf
gandalf at geochemsource.com
Wed Mar 17 08:00:49 EST 2004
Hi All!
I don't know if this is a Python problem or not. Here is a snippet:
import os
TERM='\n\r\n\r'
cmd = 'cu -l /dev/cuaa0 -s9600'
pop = os.popen4(cmd,1)
pop[0].write('AT'+TERM) # Ping modem
def readln():
buffer = ''
while True:
c = pop[1].read(1)
if c == '\n':
return buffer
elif (c != '\r') and not (c in TERM):
buffer += c
pop[1].readln()
pop[1].readln()
pop[1].readln()
Here is the problem: on FreeBSD, this works fine. The last readln()
calls will print this:
'Connected.'
''
'OK'
But if I try to do the same on Linux (with /dev/ttyS0 instead of
/dev/cuaa0) I get this:
1. The first read blocks.
2. When I do 'killall cu' in another shell, it starts to read this:
'\0x7Connected.'
'cu: Got interrupt signal'
It seems that the first line ('Connected.') if buffered somewhere. I
guess 'OK' is also buffered but it is not read because of the interrup.
Is it a problem with Linux of Python? Or is it a big difference between
/dev/ttyS0 and /dev/cuaa0?
Thanks in advance,
G
More information about the Python-list
mailing list