Capture print statements from Python script in output window

Capture print statements from Python script in output window

5

    Oct 02, 2015#1

    Does anybody know how to capture outputs/print statements from a python script running through a user tool?

    As of right now I can't seem to get the statements to update as they're printed like they do if I run the script from a python shell, or a plugin with Notepad++. I get all statements at the very end of the script, which makes the print statements not very useful. In my tool configuration I have the following settings:

    Code: Select all

    Command:
                 Menu item name:
                    Run Script in Python
                 Command line:
                    C:\Python27\ArcGIS10.2\python.exe %F
    Options:
                DOS program
                Save active file
    
    Output:
               Show DOS box
               Capture output
               Output to list box
               Captured output
    I've found a few other threads regarding this, but no solutions. Thanks for any input you might be able to provide.

    6,675585
    Grand MasterGrand Master
    6,675585

      Oct 03, 2015#2

      Hm, everything looks right. UltraEdit should open a console window with those settings and output written by console version of Python interpreter into the console window should be displayed in the "DOS box" and additionally captured by UltraEdit to list everything finally in output window.

      If I configure a user tool with your settings with selecting No replace instead of Captured output for Replace selected text with and with command line changed to C:\Temp\Test.bat "%f" and the batch file contains the lines

      Code: Select all

      @echo off
      dir "%~dp1"
      pause
      and running this tool, a console window opens listing everything in directory of active file and waiting for a key press to finish. Once I pressed the key RETURN, the window closes as batch processing finished and I see the lines captured to output window.

      Do you have read already showing captured output as program runs? and Setting up UE to run the Python interpreter?

      What happens with your command line changed to C:\Python27\ArcGIS10.2\uepython.bat "%f" and batch file containing the line:

      Code: Select all

      @C:\Python27\ArcGIS10.2\python.exe %*
      Does it make a difference regarding displaying the output written to stdout or stderr by your application respectively Python interpreter?
      Best regards from an UC/UE/UES for Windows user from Austria

      5

        Oct 05, 2015#3

        I read those previous posts with no luck. Python runs the same with no print statements given until the script has finished. I even tried running it as a Microsoft Program, with the same results.
        I tried your suggestions, but unfortunately I'm still getting all print statements at the end of the script. Not sure what the issue is

        6,675585
        Grand MasterGrand Master
        6,675585

          Oct 06, 2015#4

          Do you see all Python output immediately when you open a command prompt window and run from within this window the Python interpreter with your script?

          What happens when running from command prompt window Python with your script and output is redirected into a log file which is opened for viewing in UltraEdit while the script runs? Do you see each output directly in log file?

          Some applications detect if output is written directly to console and do a flush after every line (after each \n - line end flush) while when output is redirected to a file buffer the output stream is flushed only after every few KB (usually 4 KB) and of course at end of application.

          What happens when configuring in UltraEdit for the user tool to show DOS box, but do not capture the output?
          Best regards from an UC/UE/UES for Windows user from Austria

          5

            Oct 06, 2015#5

            Configuring in UltraEdit for the user tool to show DOS box, but not to capture the output worked! Now I'm seeing all my print statements as I should in the DOS box.
            Thank you so much for you help with this issue, you're a life saver!