[Python] AutoIt StdoutRead does not capture python logging module to stdout

Discussão em 'Python' iniciado por Stack, Agosto 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to get the full stdout output of my python script execution available in my AutoIt calling script, I just noticed that the standard logging call is not captured by StdoutRead function in autoit.

    #include "Constants.au3"
    #pragma compile(Console, true)
    #AutoIt3Wrapper_Change2CUI=Y

    Func ExecTestScript($command, $useEnv="")
    Local $line
    Local $pid = Run("cmd.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD)
    StdinWrite($pid, 'cd "' & @ScriptDir & '"' & @CRLF)
    If StringLen($useEnv) > 0 Then
    StdinWrite($pid, "conda activate " & $useEnv & @CRLF)
    EndIf
    Local $cmd = $command & @CRLF
    ConsoleWrite($cmd & @CRLF)
    StdinWrite($pid, $cmd)
    StdinWrite($pid, "exit" & @CRLF)
    Local $nChars
    While 1
    $nChars = StdoutRead($pid)
    If @error Then ExitLoop
    If @extended > 0 Then
    ConsoleWrite("++ " & $nChars & @CRLF)
    $line &= $nChars
    EndIf
    WEnd
    ProcessClose($pid)
    return $line
    EndFunc

    Local $res = ExecTestScript('python myTestScript.py', 'py38')


    My simple Python script:

    import logging

    logging.warning("Warning this could HURT!")

    print(f'Hello world!')


    Here is the debug output of my autoit script.

    [​IMG]

    As you can see the logging instruction appears in SciTe Output but not by means of my script which is logging in green.

    The SciTe output also captures the Microsoft message when DOS command prompt is opened.

    Does someone has a solution or idea of the issue?

    Continue reading...

Compartilhe esta Página