Obtaining the stdout of a running background process

394 views
Skip to first unread message

Mr Magoo

unread,
Jun 30, 2015, 6:33:30 AM6/30/15
to robotframe...@googlegroups.com
Good morning,

I have the situation whereby I am starting a background process with the 'Start Process' keyword and obtaiing its handle. The process monitors a text file for content and changes state based on that content, the new state is then reported to stdout.

My question is how do I access what is output on stdout?

From what I can see the 'Get Process Result' keyword only works on process output once that process has finished.

Is there some way I can redirect the output to a temporary text file?

Many thanks in advance,
Adam

Mr Magoo

unread,
Jun 30, 2015, 11:40:06 AM6/30/15
to robotframe...@googlegroups.com
Hi,

An update on earlier with a bit more information about what I've been trying.

I need to monitor the output of a running process until the reported status is what I am expecting. This process watches a text file for an instruction to do something then reports to stdout what it is doing. I could see no easy way of doing this via existing keywords so have gone down a fairly convoluted route.

I start the process and pipe the stdout to a text file, and check the process is running:

Start Command Manager And Check Process Is Running
    ${prochandle} =    Start Process    ./my_process    stdout=stdout.txt
    Process Should be running    ${prochandle}
    Set Suite Variable    ${prochandle}

I modify the text file that the process is watching for changes and uses as an input

Change Mode
    ${modestr} =     set variable     ModeChangeText
    Create file     /where/the/file/is/mode.txt    ${modestr}

I wait for a few seconds to make sure the process has had time to begin populating the output file (I know sleep is unreliable but I'm open to suggestions here):

Wait For Mode Change
    Sleep    5s

I then loop over the lines in the output file waiting for a keyword to match, but this is where I'm coming unstuck. The file is being continuously added to, so I need to re-initialise the ${lines} counter during each loop which just looks really unwieldy and probably wrong.

Loop Over Output File And Check For TextIWantToMatch
    ${filecontents} =    Get File    stdout.txt
    @{lines} =    Split to lines    ${filecontents}
    :FOR    ${line}    IN    @{lines}
    \    Wait Until Keyword Succeeds    0m    30s    Strings Should Match    ${line}    TextIWantToMatch
    \    ${filecontents} =    Get File    stdout.txt
    \    @{lines} =    Split to lines    ${filecontents}

*** keyword ***
Strings Should Match
    [arguments]    ${stdoutstr}    ${comparisonstr}
    ${status} =    Should Be Equal    ${stdoutstr}    ${comparisonstr}

Is there an easier way to continuously 'watch' the content of a growing log file for a particular text string?

Many thanks in advance for any help with this one

Adam
Reply all
Reply to author
Forward
0 new messages