# Obtain the output with robotframework of SSH session

**URL:** <https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115>\
**Category:** SSHLibrary\
**Created:** [22 August 2023 14:04 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115 "2023-08-22T14:04:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CarlosPitero](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@CarlosPitero](https://forum.robotframework.org/u/CarlosPitero)\
**Post date:** [22 August 2023 14:04 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115/1 "2023-08-22T14:04:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [22 August 2023 15:13 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115/2 "2023-08-22T15:13:42Z")

</div>

Hi Carlos,

In the documentation for [Execute Command](http://robotframework.org/SSHLibrary/SSHLibrary.html#Execute%20Command), you want the `return_stderr` option

The documentation provides this example:

```python
{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.

---

<div class="post-metadata">

**Author:** ![CarlosPitero](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@CarlosPitero](https://forum.robotframework.org/u/CarlosPitero)\
**Post date:** [22 August 2023 15:25 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115/3 "2023-08-22T15:25:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CarlosPitero](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@CarlosPitero](https://forum.robotframework.org/u/CarlosPitero)\
**Post date:** [22 August 2023 15:30 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115/4 "2023-08-22T15:30:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [23 August 2023 00:37 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115/5 "2023-08-23T00:37:42Z")

</div>

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:

```python
***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

```

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/2/2604e89d8ff3854bac2d75a5fdf35fd97ef4084c.png)

Dave.

---

<div class="post-metadata">

**Author:** ![CarlosPitero](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@CarlosPitero](https://forum.robotframework.org/u/CarlosPitero)\
**Post date:** [23 August 2023 07:45 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115/6 "2023-08-23T07:45:26Z")

</div>

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:  
 ![Capture](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/1/1d46177eb22973b81840d2e4435100bb167d1ffd.png)

I tried to the same with RobotFramework but I not obatin anything:

 ![Capture](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/c/ce6e418c00d49f734b1e93ad899b8991950420a9.png)

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [23 August 2023 16:04 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115/7 "2023-08-23T16:04:28Z")

</div>

Hi Carlos,

Ah Ok, this part of your command `> /tmp/BLCMD` is redirecting the stdout to the file `/tmp/BLCMD`so you can either

1. not redirect to the file, something like this

```python
{stdout} ${stderr}= Execute Command echo “laqShow” return_stderr=True

```

1. or read the file after running the command, something like this

```python
{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.

---

<div class="post-metadata">

**Author:** ![CarlosPitero](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@CarlosPitero](https://forum.robotframework.org/u/CarlosPitero)\
**Post date:** [24 August 2023 06:50 UTC](https://forum.robotframework.org/t/obtain-the-output-with-robotframework-of-ssh-session/6115/8 "2023-08-24T06:50:16Z")

</div>

Hi Dave,

Thank you very much. The code has works correctly with your help!!! Thanks a lot!!

Carlos
