0

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.

Dro
  • 1
  • 1
  • Maybe this question is better suited for the [Linux&Unix](https://unix.stackexchange.com/) or [SuperUser](https://superuser.com/) sites – mnestorov Sep 16 '20 at 07:12

1 Answers1

0

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.

that other guy
  • 116,971
  • 11
  • 170
  • 194
  • Thank you for your quick reply. If we do not need to worry about attaching from different terminals and we assume one terminal or one type of terminal can attach, is there a way to control the behavior of the screen outbuf stream? After setting stty -onlcr, I believe the extra characters that we are getting are the column position of each response [6C being the 6th column, but I can't understand why xterm would not have those extra characters even though it prints identical response on the terminal and the stty setting is set to stty -onlcr – Dro Sep 15 '20 at 19:40
  • As far as I know, screen does not support this since it's unrelated to its purpose. Use a different tool instead or in addition. – that other guy Sep 15 '20 at 19:48
  • My goal is to not have the column position in the revived packets while attached to a screen session. – Dro Sep 15 '20 at 19:49
  • The reason I use screen is to launch a background command processor app at the boot time and attach and detach on demand from an external app. running the command processor later on causes some issues with our RTOS and screen and tmux seemed to be a good solution to start apps through rc.local and attach to them later on. – Dro Sep 15 '20 at 19:54
  • You can get the data from `script` as mentioned, whether or not `script` runs in a screen session – that other guy Sep 15 '20 at 20:01