Configure a screen session to behave exactly like an xterm terminal

557 views Asked by At

I want to be able to configure a screen session through screenrc or within a session to behave just like an xterm terminal. Currently I have a c# app that uses ssh.net libraries to ssh to a Linux box from a windows machine where I attach to a screen session and send commands and receive responses back. I see two different kind and responses for the same command if I am attached to a screen session compare to when I am not attached to a screen session. To demonstrate the problem I will duplicate the issue using a putty terminal and log the data.

  1. Open a putty terminal from windows
  2. Change the Session->Logging setting and select SSH Packets, also browse to a location to save the putty.log file
  3. Set your IP address and connect to a Linux machine
  4. Once logged in, issue the following command printf "abc\6\n", this string contains an ack character
  5. the response will print abc and of course it would not show the \6 since it is not a printable character
  6. Open putty.log file and you will see the response packets data contains \6 which is the correct behavior.
  7. Now create a session by issuing the following command: screen -dmS test
  8. Attach to the session by issuing the following command: screen -Rr test
  9. issue the following command again printf "abc\6\n"
  10. abc will be printed as expected, but if you look at response packets data in putty.log it won't have the \6 character anymore
  11. I can solve this issue by piping the command like this printf "abc\6\n" | cat -v to convert \6 to printable form and show ^F on the screen, I would rather receive \6 in my packets data and this is not a desirable solution but at least it provides a solution to my problem.

The following is a more serious issue that I haven't been able to resolve. To demonstrate please do the following:

  1. Open a putty terminal from windows
  2. Change the Session->Logging setting and select SSH Packets and also browse to a location to save the putty.log file
  3. Set your IP address and connect to a Linux machine
  4. Once logged in, Change the stty setting by issuing the following command (tells the terminal to not replace the new line by carriage return): stty -onlcr
  5. then issue the command ls -al,
  6. The putty.log file will contain the correct set of data with no extra characters.
  7. Now create a session by issuing the following command: screen -dmS test
  8. Attach to the session by issuing the following command: screen -Rr test
  9. issue the following command again stty -onlcr
  10. issue ls -al again
  11. if you look at response packet data in putty.log it you will see that after a certain number of packets received the response will contain extra characters in front of each response. the extra characters are in the following format [13C. the numbers between [ and C varies.

I would like to make my responses behave the same way as an standard xterm terminal, Why is there a difference and is there a way to configure the screen to get responses consistent with a xterm type of terminal.

1

There are 1 answers

5
that other guy On

You are asking to do something that fundamentally goes against what screen does.

screen is a terminal emulator just like xterm. It interprets a stream of data from a pty and renders it internally in a buffer to keep track of what's on screen where with which formatting.

When you attach it, screen synthesizes a new stream of terminal instructions to redraw this same buffer on your particular terminal.

It can't simply store and replay the same linear stream, because this would break the seamless multiplexing and reattaching (potentially from different terminals) that is the point of the tool.

If you want a faithful dump of the linear stream of data that goes to the terminal, you can instead use script.