Getting stdout from applications like pdb



  • Hello i'm trying to get stdout from python debugger pdb.

    @connect(&process,SIGNAL(readyReadStandardOutput()),this,SLOT(printOutput()));
    process.start("python /usr/bin/pdb tmp.py")@

    but unfortunaly i have no output in this case, but if i trying to do:

    @process.start("python /usr/bin/pdb --help")@

    stdout catched perfectly. How can i catch stdout from app like pdb (or gdb)?



  • Is it possible that pdb uses stderr as its default output channel?



  • It is also possible that you're running into a know issue for these kinds of things: stdout buffering. I quote a message from "Thiago":http://comments.gmane.org/gmane.comp.lib.qt.general/44548 on from gmane.org:
    [quote] C library's behaviour is that stdout is line-buffered if it's connected to a
    terminal, but fully buffered if it's not. When QProcess spawns a child process,
    it's using a pipe (not a terminal), so the child process probably uses full
    buffering.

    You must cause it to flush its buffer more often. There's no workaround on
    Windows.

    If you were on Unix, you could force the behaviour by using a pseudoterminal
    connection. Qt wouldn't help you here, but it would be possible.[/quote]

    On the workaround: take a look at unbuffer (available for Linux).



  • [quote author="Lukas Geyer" date="1334740467"]Is it possible that pdb uses stderr as its default output channel?[/quote]

    No, i don't think so. I've tried to use also @process.readAllStandardError()@ without any results



  • [quote author="Andre" date="1334741128"]It is also possible that you're running into a know issue for these kinds of things: stdout buffering. I quote a message from "Thiago":http://comments.gmane.org/gmane.comp.lib.qt.general/44548 on from gmane.org:
    [quote] C library's behaviour is that stdout is line-buffered if it's connected to a
    terminal, but fully buffered if it's not. When QProcess spawns a child process,
    it's using a pipe (not a terminal), so the child process probably uses full
    buffering.

    You must cause it to flush its buffer more often. There's no workaround on
    Windows.

    If you were on Unix, you could force the behaviour by using a pseudoterminal
    connection. Qt wouldn't help you here, but it would be possible.[/quote]

    On the workaround: take a look at unbuffer (available for Linux).
    [/quote]

    Yes, maybe it could help. How can a send some chars to stdin of QProcess application?



  • Not sure if you're still looking for this, but I am doing something similar and figured out that you can flush the buffer by doing:

    @process.write("sys.stdout.flush();sys.stderr.flush()");@

    That'll force the python/pdb to flush the buffer and you'll be able to hook into the reading and signals properly after that.

    Edit 1:
    Sorry…you have to include a “\n” at the end of the line…so:

    @process.write(“sys.stdout.flush();sys.stderr.flush()\n”);@

    Edit 2:
    And actually, following up - this is inserted into the frame where the code is, so you cannot guarantee that the sys module has been imported, so you have to import it:

    @process.write("import sys;sys.stdout.flush();sys.stderr.flush()\n");@

    It so happened in the example I setup, I had already imported the sys module so it worked.



  • moderators note:
    @ehulser: I have merged your three consecutive postings into a single one. If you want to add to a previous posting, especially if there have been no other replies in the mean time, please edit your previous post instead of creating a new one. Also, please use @ tags to surround code sections, so they can be properly formatted.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.