0 votes
by (150 points)

Hi,

Sometimes I'm getting the last character from the VT response duplicated. I'm using DataReceived event of the VirtualTerminal object.

For example, the following raw response:

2018-10-05 14:29:16.472 VERBOSE VirtualTerminal(0)[20] Scripting: WaitFor: data received, reset last data received time stamp.
2018-10-05 14:29:16.472 VERBOSE VirtualTerminal(0)[20] Scripting: WaitFor: processing received data.
2018-10-05 14:29:16.472 DEBUG Ssh(27)[20] Info: Received 320 bytes of data.
2018-10-05 14:29:16.472 VERBOSE Ssh(27)[20] Info: Received data: 
 0000 |72-65-61-64-20-2F-65-78 70-6F-72-74-2F-68-6F-6D| read /export/hom
 0010 |65-2F-67-65-6E-65-76-61 2F-5F-5F-64-65-63-72-79| e/geneva/__decry
 0020 |70-74-65-64-5F-72-73-6C 73-5F-69-64-31-30-33-38| pted_rsls_id1038
 0030 |2F-50-61-6C-5F-43-68-61 72-74-4F-66-41-63-63-6F| /Pal_ChartOfAcco
 0040 |75-6E-74-73-2E-72-73-6C 20-0D-1B-5B-41-1B-5B-43| unts.rsl ..[A.[C
 0050 |1B-5B-43-1B-5B-43-1B-5B 43-1B-5B-43-1B-5B-43-1B| .[C.[C.[C.[C.[C.
 0060 |5B-43-1B-5B-43-1B-5B-43 1B-5B-43-1B-5B-43-1B-5B| [C.[C.[C.[C.[C.[
 0070 |43-1B-5B-43-1B-5B-43-1B 5B-43-1B-5B-43-1B-5B-43| C.[C.[C.[C.[C.[C
 0080 |1B-5B-43-1B-5B-43-1B-5B 43-1B-5B-43-1B-5B-43-1B| .[C.[C.[C.[C.[C.
 0090 |5B-43-1B-5B-43-1B-5B-43 1B-5B-43-1B-5B-43-1B-5B| [C.[C.[C.[C.[C.[
 00A0 |43-1B-5B-43-1B-5B-43-1B 5B-43-1B-5B-43-1B-5B-43| C.[C.[C.[C.[C.[C
 00B0 |1B-5B-43-1B-5B-43-1B-5B 43-1B-5B-43-1B-5B-43-1B| .[C.[C.[C.[C.[C.
 00C0 |5B-43-1B-5B-43-1B-5B-43 1B-5B-43-1B-5B-43-1B-5B| [C.[C.[C.[C.[C.[
 00D0 |43-1B-5B-43-1B-5B-43-1B 5B-43-1B-5B-43-1B-5B-43| C.[C.[C.[C.[C.[C
 00E0 |1B-5B-43-1B-5B-43-1B-5B 43-1B-5B-43-1B-5B-43-1B| .[C.[C.[C.[C.[C.
 00F0 |5B-43-1B-5B-43-1B-5B-43 1B-5B-43-1B-5B-43-1B-5B| [C.[C.[C.[C.[C.[
 0100 |43-1B-5B-43-1B-5B-43-1B 5B-43-1B-5B-43-1B-5B-43| C.[C.[C.[C.[C.[C
 0110 |1B-5B-43-1B-5B-43-1B-5B 43-1B-5B-43-1B-5B-43-1B| .[C.[C.[C.[C.[C.
 0120 |5B-43-1B-5B-43-1B-5B-43 1B-5B-43-1B-5B-43-1B-5B| [C.[C.[C.[C.[C.[
 0130 |43-1B-5B-43-1B-5B-43-1B 5B-43-1B-5B-4B-6C-0D-0A| C.[C.[C.[C.[Kl..

produces the following line in the StrippedData property:

read /export/home/geneva/__decrypted_rsls_id1038/Pal_ChartOfAccounts.rsl \rl\r\n

It's OK to see extra space and CR/LF characters in the response line, but there is an extra char 'l' at the end.
Assuming that the prompt was "runrep> " replaying the ESC sequence from the above response produces the correct line:

read /export/home/geneva/__decrypted_rsls_id1038/Pal_ChartOfAccounts.rsl

I know that you guys are just trimming ESC codes from the response without replaying them, but in this case it produces an unexpected result.

Please advice how we can handle this.

Thank you.

1 Answer

0 votes
by (72.7k points)

This is very unpleasant behavior of the server.

The remote shell was not designed to be read by automated process, but by a human user. So the server can send any data to produce .../Pal_ChartOfAccounts.rsl text on the screen (which it does).

The only possible way in this case is to interpret escape sequences and act accordingly.

You can try some workarounds, which causes the server will not send text data mixed with escape sequences.

  1. Try to use wider screen. Default is 80 columns, so try to use e.g. 120 columns: new VirtualTerminal(120, 25).

  2. I suppose the read /export/.../Pal_ChartOfAccounts.rsl is echo of the command. Try to send the command char by char with some small delays, simulating human user input.

  3. Try to use the Shell class with ShellMode.WellKnownShell. It is simple class designed for simple scenarios. It can be useful for you in this case. It can be created like this:

    var client = new Ssh();
    client.Connect();
    client.Login();
    var shell = client.StartShell(ShellMode.WellKnownShell);

...