How to get the response from command in Robot framework

Hi,
I need to create program which log in to server run there some command and get the result because depending of result I need to do something else. I can log in to server and run command but I cannot get the output. I’ll be glad if someone could help me.
Here is the program:

Run Script via SSH
    [Tags]   DEV2
    Open Connection  ${IP}    22
    ${output}=   Login   ${A_USER}   ${A_PASS}
    Should Contain   ${output}   Last login 
    Write  cd json
    ${outputs}    Execute Command    ctm build create_job.json
    Log To Console   ${outputs}
    Close All Connections 

Best regards

Hi Przemyslaw,

Firstly it looks like you are missing an equals (=), not sure if this is related or not?

${outputs}=    Execute Command    ctm build create_job.json

Next, Is the output from your command ctm build create_job.json returned to the stdout or the stderr? Does it even output any text at all or maybe just returns a return code?
Based on the way you are calling Execute Command you are only getting the stdout, perhaps you need to get the stderr as well?

${stdout}    ${stderr}=    Execute Command    ctm build create_job.json    return_stderr=True
Log To Console ${stdout}
Log To Console ${stderr}

Beyond that, you could also try one of the Read keywords and see if you can use one of them to get what you are after.

Hopefully that helps,

Dave.

Hi Dave,
thanks for this because now I see where is the problem but maybe someone have an idea how to resolve this? Because I do not understand how could be the problem with authorizations after successfully connected to the server.

Hi Przemyslaw,

Well because that error is in your stderr then it’s come from your ctm executable or what ever it’s interacting with so it’s probably beyond what anyone in this forum can help you with.

  • I would suggest you start by checking the contents of create_job.json to see if there is a username and password in there (or a place for them)?
  • next I’d try manually creating a ssh session to that machine with the same user and password and running that command (ctm build create_job.json) in that ssh session and see if you get the same error or something else
    • if something else then you have to look at what’s different from your ssh session to the ssh session robot creates, pay close attention to the variables especially any variables related to proxy servers, you might want to start by manually connecting a ssh session to that host with that user and pass, run printenv and store the result, then in your test do a ${stdout} ${stderr}= Execute Command printenv return_stderr=True and compare the results

Unfortunately I don’t think this is the best place to get help with errors from what ever ctm build is.

Hope that helps,

Dave.