How to get process result after timeout

I have a test program that just prints ‘Hello World!’ to stdout every second in an endless loop.
In robot I run the process with a timeout of 3 seconds and, after that, I want to print/check the program output to stdout, but it seems that, when the process timeout, the result is not stored (result.stdout is empty).

This is the simple test I am doing:

*** Settings ***
Library     Process
Test Teardown   Terminate All Processes

*** Variables ***
${PROGRAM}      ../../hello-linux

*** Test Cases ***
Execute Hello Program
    ${result}=        Run Process     ${PROGRAM}   timeout=3s
    Log To Console  Result: ${result.stdout}

As I said, ${result.stdout} is empty. If I run the /bin/ls program instead (that doesn’t timeout) it works as expected.

How can I check the program output to stdout when it timeout?

Have you tested this with a script that only prints Hello World! once and thus ends cleanly before the timeout? Have you checked what ${result.stderr} contains?

Thanks @pekkaklarck for the reply. I already tried what you suggest. If I modify the program to exit cleanly after printing out a few Hello World! strings it works as expected.

With the original program, when the process timeouts both ${result.stdout} and ${result.stderr} are empty. It is like those fd were not flushed.

I have solved this redirecting the hello-world program’s output to a file and using the stdbuf command, that allows to change the buffering before executing the program:

*** Test Cases ***
Hello Program Prints Hello World
    [Tags]      HELLO
    Remove File         ${OUTPUTFILE}
    Run Process   stdbuf -o0 -e0 ${PROGRAM} >${OUTPUTFILE}    timeout=3s     shell=True
    ${content}=         Get File    ${OUTPUTFILE}
    Should Contain      ${content}    Hello World!
    Remove File         ${OUTPUTFILE}

Not sure if this is the most elegant solution, though

Note that you can get the stdout directly without the need of the output file

Hello Program Prints Hello World
[Tags] HELLO
${result}= Run Process stdbuf -o0 -e0 ${PROGRAM} timeout=3s shell=True
Should Contain ${result.stdout} Hello World!

You can also redirect outputs to a file with Run Process directly. Just use stdout=${path}.