Hi,
I want to obtain the output about a command that I execute on SSH session. I don’t want to obtain if the command has been executed with success, I need to obtain the output.
My code is:
Open Connection ${IP}
Login ${User} ${Password}
${output} Execute Command laqShow
Log ${output}
Close Connection
But in the output, I have not the correct result.
The output when you execute that command is:
Module 1 offline
Module 2 offline
I have tested with many keywords (about the SSHLibrary) but I have no succes whith that. Could you know the way to resolve this issue?
Hi Carlos,
In the documentation for Execute Command, you want the return_stderr
option
The documentation provides this example:
{stdout} ${stderr}= Execute Command echo 'Hello John!' return_stderr=True
If the command follows POSIX standards and stderr returned is 0 then the “command has been executed with success” otherwise it a non success.
So start with that and see how you go.
Dave.
Hi Dave,
Thanks for the information but i don’t have that 0 if the command has been executed with success or the opposite. I want to save in a variable the output that you obtain when execute the command.
I don’t know if I have explained myself well.
Carlos.
Hi Dave,
For example if I execute “ifconfig”, In the SSH session I obtain an information about the networks configurations so I want to save that information in some way because I need to analyse after and I have been tried with the SSHLibrary and his keywords but without success.
Thanks!
Carlos
Hi Carlos,
Sorry I made a mistake (That’s what I get for replying to posts at 1am )
You need return_rc=True
not return_stderr=True
Here’s an example:
*** Test Cases ***
Carlos Pitero 1
Open Connection ${IP}
Login ${User} ${Password}
${output} ${rc}= Execute Command ifconfig return_rc=True
Log ${rc}
IF ${rc} == 0
Log command has been executed with success
ELSE
Log command failed with error level ${rc}
END
Log ${output}
Close Connection
Dave.
Hi Dave,
Thank you very much for the information. That code works correctly but with linux commands that I need to use does not work as expected.
I put on the console this command “tty > /tmp/BLCMD” and then the another one “echo “laqShow” > /tmp/BLCMD”. When I put the last one, I obtain in the console:
I tried to the same with RobotFramework but I not obatin anything:
Hi Carlos,
Ah Ok, this part of your command > /tmp/BLCMD
is redirecting the stdout to the file /tmp/BLCMD
so you can either
- not redirect to the file, something like this
{stdout} ${stderr}= Execute Command echo “laqShow” return_stderr=True
- or read the file after running the command, something like this
{stdout} ${stderr}= Execute Command echo “laqShow” > /tmp/BLCMD return_stderr=True
Log ${stderr}
{stdout}= Execute Command cat /tmp/BLCMD
Log ${stdout}
It depends if you really need to create that BLCMD file or not?
Dave.
Hi Dave,
Thank you very much. The code has works correctly with your help!!! Thanks a lot!!
Carlos
1 Like