Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Getting stdout from applications like pdb
Forum Updated to NodeBB v4.3 + New Features

Getting stdout from applications like pdb

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qmor
    wrote on last edited by
    #1

    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)?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qmor
          wrote on last edited by
          #4

          [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

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qmor
            wrote on last edited by
            #5

            [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?

            1 Reply Last reply
            0
            • E Offline
              E Offline
              ehulser
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved