Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-1442

ssh exec handling forces LF-CRLF conversion

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 23.1
    • Fix Version/s: OTP-23.2.3
    • Component/s: ssh
    • Labels:
      None

      Description

      I have a use case that would be made very convenient by using the ssh exec feature. Basically a shell script would ssh into an Erlang node and run a command. The shell script captures the output and processes it.

      My understanding of the ssh exec feature is that I can either return the output of the command being exec'd or write to stdout. The output is large and would be easier to write incrementally to stdout. I found out that when writing to stdout, LF characters are always converted to CRLF sequences. This breaks the program at the other side of the pipe. 

      The following modification to `ssh_cli.erl` fixes the issue:

      $ git diff -w
      diff --git a/lib/ssh/src/ssh_cli.erl b/lib/ssh/src/ssh_cli.erl
      index 653c65d949..3f781b53b3 100644
      --- a/lib/ssh/src/ssh_cli.erl
      +++ b/lib/ssh/src/ssh_cli.erl
      @@ -487,7 +487,7 @@ conv_buf([13, 10 | Rest], _AccBuf, AccBufTail, AccWrite, _Col) ->
       conv_buf([13 | Rest], _AccBuf, AccBufTail, AccWrite, _Col) ->
       conv_buf(Rest, [], tl1(AccBufTail), [13 | AccWrite], 0);
       conv_buf([10 | Rest], _AccBuf, AccBufTail, AccWrite, _Col) ->
      - conv_buf(Rest, [], tl1(AccBufTail), [10, 13 | AccWrite], 0);
      + conv_buf(Rest, [], tl1(AccBufTail), [10 | AccWrite], 0);
       conv_buf([C | Rest], AccBuf, AccBufTail, AccWrite, Col) ->
       conv_buf(Rest, [C | AccBuf], tl1(AccBufTail), [C | AccWrite], Col + 1).
      

      This isn't the right fix, though.

      I don't see any other easy way of changing this behavior. Am I missing something? If not, what would be the "right" way to add the ability to disable NL->CRNL conversion here?

        Attachments

          Activity

            People

            Assignee:
            hans Hans Nilsson
            Reporter:
            fhunleth Frank Hunleth
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: