I'm a new person in world of python and I've a problem with buffering (but I think is not exactly python problem). I want write my own debugger under linux. I need redirect stdin, stdout and stderr to different descriptor, because I want show output in my debugger console.
So code is:
mylib = CDLL("libc.so.6")
self.pid = os.fork()
if (self.pid == 0):
c = os.open("myfile", 1, 0)
os.dup2(c,0)
os.dup2(c,1)
os.dup2(c,2)
mylib.ptrace(ptraceRequest.PTRACE_TRACEME, 0, 0, 0)
os.execl("Fib.out", "Fib")
sys.exit()
else:
print(self.pid)
The problem is in execl. I don't know why, but streams are buffered (or I think that buffering is source of my problem :) ). So my testing program Fib.out (it display first five value of fibonacci sequence with 5 sec break between values) is visible only after Fib.out is finished.
I changed third argument in os.open - documentations says that 0 as third argument means no buffering, but this don't work for me. When output is redirected on /dev/pts/12 - everything works fine. Its looks for me like the problem can be connected with default value of streams buffer.
In C we have 'setvbuf', but in python I can't find nothing what will be similar - I only can found information that I should use os.open with 0 or 1 value (as third argument)
Maybe it is wrong way of thinking about problem? Do you know any better idea to show program output in my own console?