Menu

stdout and stderre redirection

Help
Anthony T.
2009-07-20
2013-04-06
  • Anthony T.

    Anthony T. - 2009-07-20

    Hello,

    I'am "playing" with PythonQt -- whose concept I find very nice :-) -- and doing so I'm trying to "say hello" (original isn't it ?) from inside a Python script with a "print" instruction.

    However I connect the "pythonStdOut(const QString &str)" signal, whether I use or not the "PythonQt::RedirectStdOut" option I do not manage to get anything from the Python print statement back in my C++ main program.

    I dived into the code and tried step by step debugging but could not spot anything obvious enougt for me to notice. Could anyone please give me a working example of redirection so that I can test it on my system (Unbuntu Jaunty 64 - Qt 4.5.0) ?
    Or any insight about what I missed ?

    Of course, in case there's a bug, I'm willing to try and fix it and send the patch :-)

    Thanks,
    --
    Anthony
    (PhD Student)

     
    • Florian Link

      Florian Link - 2009-07-20

      Hm, did you try one of the examples that makes use of the PythonQtScriptingConsole? Those examples make use of the redirection to print stdout on the scripting console. Hope that helps!

       
      • Anthony T.

        Anthony T. - 2009-07-21

        Yes I tried but I got a bunch of Qt cursor related errors... and no output either on th ScriptingConcole or on the "real" console.

        But yesterday afternoor I solved the specific problem I faced : it was twofold.
        First I didn't read the Doxygen carefully enought : the default flag for PythonQt::init() DOES includes redirection, it is thus OK that when just doing init() I don't get anything on the standard console. Second the print statement in Python generates 3 *distinct* PythonQt::pythonStdOut event : the actual string printed, the empty string and the new line. The fix was to use directly sys.stdout.write !

        I does understand the newline in a separate event : it is python's print implementation related. But I didn't get the point of PythonQtStdOutRedirect::softspace : could you please tell me the big picture about it ?

        Thanks for your reactivity anyway :-)

         
  • superfisi

    superfisi - 2011-04-11

    Hi there,

    currently I am facing a similar problem… I connected the signals for stdout and stderr and it works fine.

    My problem is: If a certain Python-script has e.g. a syntax error in it, I never get any output from PythonQt.

    Calling the buggy script directly from the console (in order to get more output) is often very difficult because certain imports in it directly point to PythonQt-Wrapper-classes (for some of them I already created some Moc-Classes).

    So my question is: Is there any way to get "more information"? Sth. like the "real Python console output"?

    Thanks in advance & Keep up the good work!

    BR, Alex

     
  • Florian Link

    Florian Link - 2011-04-12

    I don't understand your question. If you are connecting to stdout/stderr (and passed the PythonQt::RedirectStdOut flag to PythonQt::init()), you will get all outputs into your Qt application via the signals and it is up to you to print those. These are exactly the same outputs as what you would get in stdout/err on a console.

    If you do not redirect the outputs, they are going to std output, so you may as well compile your application (if you are on windows) using the "console" setup so that you can see all outputs in the dos box (on Linux and Mac they are always visible).

    Appart from that, if you are using the PyScriptingConsole GUI that comes with PythonQt, this will display all outputs as well (have a look at the examples that make use of the scripting console.

    regards,
    Florian

     
  • superfisi

    superfisi - 2011-05-11

    Hi Florian,

    sorry for not answering since. You are absolutely right… PythonQt does everything fine (meaning it does emit all outputs to std::err and atd::out correctly via signals); we could'nt find some output in our logfile, but the problem was on our side… the application crashed before the signal could be "processed".

    Thanks and best regards,

    Alex

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.