# Sending commands, retrieving outputs and screenshot results via SSH library and Process

**URL:** <https://forum.robotframework.org/t/sending-commands-retrieving-outputs-and-screenshot-results-via-ssh-library-and-process/7273>\
**Category:** SSHLibrary\
**Created:** [9 May 2024 20:39 UTC](https://forum.robotframework.org/t/sending-commands-retrieving-outputs-and-screenshot-results-via-ssh-library-and-process/7273 "2024-05-09T20:39:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacobo1451](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@Jacobo1451](https://forum.robotframework.org/u/Jacobo1451)\
**Post date:** [9 May 2024 20:39 UTC](https://forum.robotframework.org/t/sending-commands-retrieving-outputs-and-screenshot-results-via-ssh-library-and-process/7273/1 "2024-05-09T20:39:45Z")

</div>

Hello, I intend to write some testcases that involve sending commands via ssh to a remote server or devices, capturing the output (screenshot the shell output directly or creating a .txt file or similar that can be screenshot and also save the file log) to be post-processed, filtered and piping it to other processes and do the capture process again for the new outputs.

To do so started reading about the SSH and Process libraries, their basic functionality and created a robot file to test the simplest case to establish an ssh session , send a command and log the output.  
But for some reason even though it establishes a session, it gives a return code `1` for the log.

I have tested connecting to the server and sending a “show version” command, using a python script with the netmiko library and it works well.

This is the robot framework code and the output.

\*\*\* Test Cases \*\*\*  
Establish SSH connection to EPNM  
Open Connection ${epnm\_host}  
Login ${epnm\_username} ${epnm\_password}  
${output} ${stderr} ${rc} = Execute Command show version return\_stderr=True return\_rc=True

```
Log ${rc}
log ${output}
log ${stderr}

close connection

```

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

Am I missing something?  
I have also thought about writing a custom library that exposes netmiko functionality to the testcases, but would rather try to solve the issue and use the keywords from SSH library.

Other question I had is if it is possible to use first the SSH library to establish the connection and then Process to send the command and extract the info for the same session.

Lastly want to know if it is possible to take a screenshot of the actual CLI output or if it will be necessary to redirect the output to a txt file and take the screenshot from there.

I appreciate any ideas to solve the issue and for the specific testcase.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [9 May 2024 20:59 UTC](https://forum.robotframework.org/t/sending-commands-retrieving-outputs-and-screenshot-results-via-ssh-library-and-process/7273/2 "2024-05-09T20:59:00Z")

</div>

exit code 1 typically mean that the command was executed but that program encountered an error.

In this case, stderr shows “Error getty tty, exiting”. Quick googling didnt show this error message to be anything generic so most likely that is coming from your program. So the issue could be that your “show” application requires tty (or pty) for some reason and without one, it fails…

Paramiko does have feature to request a pty but I didn’t find anything in the sshlibrary code where that could be implemented.

As possible solution, on your machine where you run robot and sshlibrary, add your hostname into ssh config file and add `RequestTTY force` under that host. That _might help_

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [9 May 2024 23:56 UTC](https://forum.robotframework.org/t/sending-commands-retrieving-outputs-and-screenshot-results-via-ssh-library-and-process/7273/3 "2024-05-09T23:56:37Z")

</div>

I use the keywords `Write` and `Read` and the output is enough for my needs.

About getting screenshots, I found an article on how to get HTML mimicking the screen, which allowed me to capture the `top`or `htop` output. But this is done with a technique of “cloning” the screen, and I never tried to make a SSHLibrary keyword.

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [10 May 2024 06:48 UTC](https://forum.robotframework.org/t/sending-commands-retrieving-outputs-and-screenshot-results-via-ssh-library-and-process/7273/4 "2024-05-10T06:48:14Z")

</div>

I’d add that using Write and Read _might_ actually allocate the tty automatically. Since tty/pty is typically needed for interactive shell session so what @HelioGuilherme66 said might also a good idea to try at leasat.
