Do not clear a split screen region when one command completes

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












I run some commands in parallel and I want to see their last output after all of them complete (in the scrollback of my terminal emulator). Here's my test script test.screen:



# 
screen -t A sh -c 'echo important info && sleep 2'

split
focus

#
screen -t B sh -c 'echo another important info && sleep 5'


The launch command:



$ screen -c test.screen


Output:



[screen is terminating]
[il@reallin ~]$


--
another important info





1 B


One problem is: when the first sleep 2 completes, the printed message important info is erased. If I add zombie kr at the beginning, then screen does not exit at all. As a workaround the caller can wait for all screen processes to exit and then issue -X quit



The other problem: the caret does not move to the bottom when screen exits and the shell prompt overwrites some data. The workaround is to echo $LINES times.







share|improve this question


























    up vote
    -1
    down vote

    favorite












    I run some commands in parallel and I want to see their last output after all of them complete (in the scrollback of my terminal emulator). Here's my test script test.screen:



    # 
    screen -t A sh -c 'echo important info && sleep 2'

    split
    focus

    #
    screen -t B sh -c 'echo another important info && sleep 5'


    The launch command:



    $ screen -c test.screen


    Output:



    [screen is terminating]
    [il@reallin ~]$


    --
    another important info





    1 B


    One problem is: when the first sleep 2 completes, the printed message important info is erased. If I add zombie kr at the beginning, then screen does not exit at all. As a workaround the caller can wait for all screen processes to exit and then issue -X quit



    The other problem: the caret does not move to the bottom when screen exits and the shell prompt overwrites some data. The workaround is to echo $LINES times.







    share|improve this question
























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I run some commands in parallel and I want to see their last output after all of them complete (in the scrollback of my terminal emulator). Here's my test script test.screen:



      # 
      screen -t A sh -c 'echo important info && sleep 2'

      split
      focus

      #
      screen -t B sh -c 'echo another important info && sleep 5'


      The launch command:



      $ screen -c test.screen


      Output:



      [screen is terminating]
      [il@reallin ~]$


      --
      another important info





      1 B


      One problem is: when the first sleep 2 completes, the printed message important info is erased. If I add zombie kr at the beginning, then screen does not exit at all. As a workaround the caller can wait for all screen processes to exit and then issue -X quit



      The other problem: the caret does not move to the bottom when screen exits and the shell prompt overwrites some data. The workaround is to echo $LINES times.







      share|improve this question














      I run some commands in parallel and I want to see their last output after all of them complete (in the scrollback of my terminal emulator). Here's my test script test.screen:



      # 
      screen -t A sh -c 'echo important info && sleep 2'

      split
      focus

      #
      screen -t B sh -c 'echo another important info && sleep 5'


      The launch command:



      $ screen -c test.screen


      Output:



      [screen is terminating]
      [il@reallin ~]$


      --
      another important info





      1 B


      One problem is: when the first sleep 2 completes, the printed message important info is erased. If I add zombie kr at the beginning, then screen does not exit at all. As a workaround the caller can wait for all screen processes to exit and then issue -X quit



      The other problem: the caret does not move to the bottom when screen exits and the shell prompt overwrites some data. The workaround is to echo $LINES times.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 14 '17 at 14:42

























      asked Oct 14 '17 at 11:19









      basin

      6881721




      6881721




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          If you do not want the screen to clear when exiting "screen", you should choose (or modify) a terminal description which does not switch to the alternate screen. That is the TERM value outside screen.



          With xterm (and a few others such as PuTTY) you can configure the terminal to prevent using the alternate screen, but for most terminals which copy xterm's alternate screen feature, this is hard-coded, not configurable. So the terminal description is the place to start.



          ncurses provides a terminal description "xterm1" which has the alternate screen suppressed (and seeing that it is in Debian, it's probably in derived distributions such as Ubuntu). For other systems, it depends. Here's a difference from infocmp:



          comparing xterm1 to xterm. 
          comparing booleans.
          comparing numbers.
          comparing strings.
          rmcup: NULL, 'E[?1049l'.
          smcup: NULL, 'E[?1049h'.


          The "screen" program also has its own variant of the alternate screen which is normally off:



           altscreen on|off
          If set to on, "alternate screen" support is enabled in virtual termi‐
          nals, just like in xterm. Initial setting is `off'.


          Further reading:



          • Why doesn't the screen clear when running vi?





          share|improve this answer




















          • We're talking not about the altscreen feature of xterm and likes, but about clearing the screen's window.
            – basin
            Oct 14 '17 at 12:00










          • They are not separable, because the clearing happens using the outer terminal description. I pointed that out in the first sentence.
            – Thomas Dickey
            Oct 14 '17 at 13:59











          • adding altscreen off at the beginning of the script does not prevent clearing that region of the screen
            – basin
            Oct 14 '17 at 14:28










          • Sure: clearing the terminal on exit from screen is controlled by the outer terminal description. Inside, screen simulates its own alternate screen feature.
            – Thomas Dickey
            Oct 14 '17 at 14:32










          • I cannot use your answer
            – basin
            Oct 14 '17 at 14:41

















          up vote
          -1
          down vote



          accepted










          There's no good solution for a split screen region being cleared: zombie windows prevent screen from exiting. I had to add additional synchronization between the windows and the caller script and when they all die, I call screen -X quit explicitly.



          The altscreen command had nothing to do with this. The cursor didn't move to the bottom, because my default /etc/screenrc was half-working: the host terminal altscreen feature was used, but the altscreen wasn't cleared before switching back. To make it work by default I copied /etc/screenrc from CentOS 7 and for my case I disabled the feature completely with termcapinfo * ti=:te=.



          test.sh:



          #!/bin/bash

          # set -e

          if [ "a" = "$1" ]; then
          # decrement file name towards zero, then kill screen
          set -e
          a=-1
          cd "$COUNTERDIR"

          while true; do
          for old in *; do
          new=$((old + a))
          done
          [ 0 -eq "$a" ] || 2>/dev/null mv ./$old ./$new && break
          done

          if [ 0 -eq "$new" ]; then
          screen -X quit
          fi
          exit
          fi


          NWINDOWS=2
          COUNTERDIR=`mktemp -d`
          touch "$COUNTERDIR/$NWINDOWS"

          export COUNTERDIR

          screen -c test.screen
          rm -rf "$COUNTERDIR"


          test.screen:



          # do not use host terminal altscreen feature
          termcapinfo * ti=:te=
          # windows stay after command terminates
          zombie kr

          screen -t A sh -c 'for ((i=0; i<100; i++)); do echo important info $i; done && sleep 5; ./test.sh a'

          split
          focus

          screen -t B sh -c 'for ((i=0; i<100; i++)); do echo another important info $i; done && sleep 2; ./test.sh a'





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398093%2fdo-not-clear-a-split-screen-region-when-one-command-completes%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            If you do not want the screen to clear when exiting "screen", you should choose (or modify) a terminal description which does not switch to the alternate screen. That is the TERM value outside screen.



            With xterm (and a few others such as PuTTY) you can configure the terminal to prevent using the alternate screen, but for most terminals which copy xterm's alternate screen feature, this is hard-coded, not configurable. So the terminal description is the place to start.



            ncurses provides a terminal description "xterm1" which has the alternate screen suppressed (and seeing that it is in Debian, it's probably in derived distributions such as Ubuntu). For other systems, it depends. Here's a difference from infocmp:



            comparing xterm1 to xterm. 
            comparing booleans.
            comparing numbers.
            comparing strings.
            rmcup: NULL, 'E[?1049l'.
            smcup: NULL, 'E[?1049h'.


            The "screen" program also has its own variant of the alternate screen which is normally off:



             altscreen on|off
            If set to on, "alternate screen" support is enabled in virtual termi‐
            nals, just like in xterm. Initial setting is `off'.


            Further reading:



            • Why doesn't the screen clear when running vi?





            share|improve this answer




















            • We're talking not about the altscreen feature of xterm and likes, but about clearing the screen's window.
              – basin
              Oct 14 '17 at 12:00










            • They are not separable, because the clearing happens using the outer terminal description. I pointed that out in the first sentence.
              – Thomas Dickey
              Oct 14 '17 at 13:59











            • adding altscreen off at the beginning of the script does not prevent clearing that region of the screen
              – basin
              Oct 14 '17 at 14:28










            • Sure: clearing the terminal on exit from screen is controlled by the outer terminal description. Inside, screen simulates its own alternate screen feature.
              – Thomas Dickey
              Oct 14 '17 at 14:32










            • I cannot use your answer
              – basin
              Oct 14 '17 at 14:41














            up vote
            0
            down vote













            If you do not want the screen to clear when exiting "screen", you should choose (or modify) a terminal description which does not switch to the alternate screen. That is the TERM value outside screen.



            With xterm (and a few others such as PuTTY) you can configure the terminal to prevent using the alternate screen, but for most terminals which copy xterm's alternate screen feature, this is hard-coded, not configurable. So the terminal description is the place to start.



            ncurses provides a terminal description "xterm1" which has the alternate screen suppressed (and seeing that it is in Debian, it's probably in derived distributions such as Ubuntu). For other systems, it depends. Here's a difference from infocmp:



            comparing xterm1 to xterm. 
            comparing booleans.
            comparing numbers.
            comparing strings.
            rmcup: NULL, 'E[?1049l'.
            smcup: NULL, 'E[?1049h'.


            The "screen" program also has its own variant of the alternate screen which is normally off:



             altscreen on|off
            If set to on, "alternate screen" support is enabled in virtual termi‐
            nals, just like in xterm. Initial setting is `off'.


            Further reading:



            • Why doesn't the screen clear when running vi?





            share|improve this answer




















            • We're talking not about the altscreen feature of xterm and likes, but about clearing the screen's window.
              – basin
              Oct 14 '17 at 12:00










            • They are not separable, because the clearing happens using the outer terminal description. I pointed that out in the first sentence.
              – Thomas Dickey
              Oct 14 '17 at 13:59











            • adding altscreen off at the beginning of the script does not prevent clearing that region of the screen
              – basin
              Oct 14 '17 at 14:28










            • Sure: clearing the terminal on exit from screen is controlled by the outer terminal description. Inside, screen simulates its own alternate screen feature.
              – Thomas Dickey
              Oct 14 '17 at 14:32










            • I cannot use your answer
              – basin
              Oct 14 '17 at 14:41












            up vote
            0
            down vote










            up vote
            0
            down vote









            If you do not want the screen to clear when exiting "screen", you should choose (or modify) a terminal description which does not switch to the alternate screen. That is the TERM value outside screen.



            With xterm (and a few others such as PuTTY) you can configure the terminal to prevent using the alternate screen, but for most terminals which copy xterm's alternate screen feature, this is hard-coded, not configurable. So the terminal description is the place to start.



            ncurses provides a terminal description "xterm1" which has the alternate screen suppressed (and seeing that it is in Debian, it's probably in derived distributions such as Ubuntu). For other systems, it depends. Here's a difference from infocmp:



            comparing xterm1 to xterm. 
            comparing booleans.
            comparing numbers.
            comparing strings.
            rmcup: NULL, 'E[?1049l'.
            smcup: NULL, 'E[?1049h'.


            The "screen" program also has its own variant of the alternate screen which is normally off:



             altscreen on|off
            If set to on, "alternate screen" support is enabled in virtual termi‐
            nals, just like in xterm. Initial setting is `off'.


            Further reading:



            • Why doesn't the screen clear when running vi?





            share|improve this answer












            If you do not want the screen to clear when exiting "screen", you should choose (or modify) a terminal description which does not switch to the alternate screen. That is the TERM value outside screen.



            With xterm (and a few others such as PuTTY) you can configure the terminal to prevent using the alternate screen, but for most terminals which copy xterm's alternate screen feature, this is hard-coded, not configurable. So the terminal description is the place to start.



            ncurses provides a terminal description "xterm1" which has the alternate screen suppressed (and seeing that it is in Debian, it's probably in derived distributions such as Ubuntu). For other systems, it depends. Here's a difference from infocmp:



            comparing xterm1 to xterm. 
            comparing booleans.
            comparing numbers.
            comparing strings.
            rmcup: NULL, 'E[?1049l'.
            smcup: NULL, 'E[?1049h'.


            The "screen" program also has its own variant of the alternate screen which is normally off:



             altscreen on|off
            If set to on, "alternate screen" support is enabled in virtual termi‐
            nals, just like in xterm. Initial setting is `off'.


            Further reading:



            • Why doesn't the screen clear when running vi?






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 14 '17 at 11:52









            Thomas Dickey

            49.9k586155




            49.9k586155











            • We're talking not about the altscreen feature of xterm and likes, but about clearing the screen's window.
              – basin
              Oct 14 '17 at 12:00










            • They are not separable, because the clearing happens using the outer terminal description. I pointed that out in the first sentence.
              – Thomas Dickey
              Oct 14 '17 at 13:59











            • adding altscreen off at the beginning of the script does not prevent clearing that region of the screen
              – basin
              Oct 14 '17 at 14:28










            • Sure: clearing the terminal on exit from screen is controlled by the outer terminal description. Inside, screen simulates its own alternate screen feature.
              – Thomas Dickey
              Oct 14 '17 at 14:32










            • I cannot use your answer
              – basin
              Oct 14 '17 at 14:41
















            • We're talking not about the altscreen feature of xterm and likes, but about clearing the screen's window.
              – basin
              Oct 14 '17 at 12:00










            • They are not separable, because the clearing happens using the outer terminal description. I pointed that out in the first sentence.
              – Thomas Dickey
              Oct 14 '17 at 13:59











            • adding altscreen off at the beginning of the script does not prevent clearing that region of the screen
              – basin
              Oct 14 '17 at 14:28










            • Sure: clearing the terminal on exit from screen is controlled by the outer terminal description. Inside, screen simulates its own alternate screen feature.
              – Thomas Dickey
              Oct 14 '17 at 14:32










            • I cannot use your answer
              – basin
              Oct 14 '17 at 14:41















            We're talking not about the altscreen feature of xterm and likes, but about clearing the screen's window.
            – basin
            Oct 14 '17 at 12:00




            We're talking not about the altscreen feature of xterm and likes, but about clearing the screen's window.
            – basin
            Oct 14 '17 at 12:00












            They are not separable, because the clearing happens using the outer terminal description. I pointed that out in the first sentence.
            – Thomas Dickey
            Oct 14 '17 at 13:59





            They are not separable, because the clearing happens using the outer terminal description. I pointed that out in the first sentence.
            – Thomas Dickey
            Oct 14 '17 at 13:59













            adding altscreen off at the beginning of the script does not prevent clearing that region of the screen
            – basin
            Oct 14 '17 at 14:28




            adding altscreen off at the beginning of the script does not prevent clearing that region of the screen
            – basin
            Oct 14 '17 at 14:28












            Sure: clearing the terminal on exit from screen is controlled by the outer terminal description. Inside, screen simulates its own alternate screen feature.
            – Thomas Dickey
            Oct 14 '17 at 14:32




            Sure: clearing the terminal on exit from screen is controlled by the outer terminal description. Inside, screen simulates its own alternate screen feature.
            – Thomas Dickey
            Oct 14 '17 at 14:32












            I cannot use your answer
            – basin
            Oct 14 '17 at 14:41




            I cannot use your answer
            – basin
            Oct 14 '17 at 14:41












            up vote
            -1
            down vote



            accepted










            There's no good solution for a split screen region being cleared: zombie windows prevent screen from exiting. I had to add additional synchronization between the windows and the caller script and when they all die, I call screen -X quit explicitly.



            The altscreen command had nothing to do with this. The cursor didn't move to the bottom, because my default /etc/screenrc was half-working: the host terminal altscreen feature was used, but the altscreen wasn't cleared before switching back. To make it work by default I copied /etc/screenrc from CentOS 7 and for my case I disabled the feature completely with termcapinfo * ti=:te=.



            test.sh:



            #!/bin/bash

            # set -e

            if [ "a" = "$1" ]; then
            # decrement file name towards zero, then kill screen
            set -e
            a=-1
            cd "$COUNTERDIR"

            while true; do
            for old in *; do
            new=$((old + a))
            done
            [ 0 -eq "$a" ] || 2>/dev/null mv ./$old ./$new && break
            done

            if [ 0 -eq "$new" ]; then
            screen -X quit
            fi
            exit
            fi


            NWINDOWS=2
            COUNTERDIR=`mktemp -d`
            touch "$COUNTERDIR/$NWINDOWS"

            export COUNTERDIR

            screen -c test.screen
            rm -rf "$COUNTERDIR"


            test.screen:



            # do not use host terminal altscreen feature
            termcapinfo * ti=:te=
            # windows stay after command terminates
            zombie kr

            screen -t A sh -c 'for ((i=0; i<100; i++)); do echo important info $i; done && sleep 5; ./test.sh a'

            split
            focus

            screen -t B sh -c 'for ((i=0; i<100; i++)); do echo another important info $i; done && sleep 2; ./test.sh a'





            share|improve this answer
























              up vote
              -1
              down vote



              accepted










              There's no good solution for a split screen region being cleared: zombie windows prevent screen from exiting. I had to add additional synchronization between the windows and the caller script and when they all die, I call screen -X quit explicitly.



              The altscreen command had nothing to do with this. The cursor didn't move to the bottom, because my default /etc/screenrc was half-working: the host terminal altscreen feature was used, but the altscreen wasn't cleared before switching back. To make it work by default I copied /etc/screenrc from CentOS 7 and for my case I disabled the feature completely with termcapinfo * ti=:te=.



              test.sh:



              #!/bin/bash

              # set -e

              if [ "a" = "$1" ]; then
              # decrement file name towards zero, then kill screen
              set -e
              a=-1
              cd "$COUNTERDIR"

              while true; do
              for old in *; do
              new=$((old + a))
              done
              [ 0 -eq "$a" ] || 2>/dev/null mv ./$old ./$new && break
              done

              if [ 0 -eq "$new" ]; then
              screen -X quit
              fi
              exit
              fi


              NWINDOWS=2
              COUNTERDIR=`mktemp -d`
              touch "$COUNTERDIR/$NWINDOWS"

              export COUNTERDIR

              screen -c test.screen
              rm -rf "$COUNTERDIR"


              test.screen:



              # do not use host terminal altscreen feature
              termcapinfo * ti=:te=
              # windows stay after command terminates
              zombie kr

              screen -t A sh -c 'for ((i=0; i<100; i++)); do echo important info $i; done && sleep 5; ./test.sh a'

              split
              focus

              screen -t B sh -c 'for ((i=0; i<100; i++)); do echo another important info $i; done && sleep 2; ./test.sh a'





              share|improve this answer






















                up vote
                -1
                down vote



                accepted







                up vote
                -1
                down vote



                accepted






                There's no good solution for a split screen region being cleared: zombie windows prevent screen from exiting. I had to add additional synchronization between the windows and the caller script and when they all die, I call screen -X quit explicitly.



                The altscreen command had nothing to do with this. The cursor didn't move to the bottom, because my default /etc/screenrc was half-working: the host terminal altscreen feature was used, but the altscreen wasn't cleared before switching back. To make it work by default I copied /etc/screenrc from CentOS 7 and for my case I disabled the feature completely with termcapinfo * ti=:te=.



                test.sh:



                #!/bin/bash

                # set -e

                if [ "a" = "$1" ]; then
                # decrement file name towards zero, then kill screen
                set -e
                a=-1
                cd "$COUNTERDIR"

                while true; do
                for old in *; do
                new=$((old + a))
                done
                [ 0 -eq "$a" ] || 2>/dev/null mv ./$old ./$new && break
                done

                if [ 0 -eq "$new" ]; then
                screen -X quit
                fi
                exit
                fi


                NWINDOWS=2
                COUNTERDIR=`mktemp -d`
                touch "$COUNTERDIR/$NWINDOWS"

                export COUNTERDIR

                screen -c test.screen
                rm -rf "$COUNTERDIR"


                test.screen:



                # do not use host terminal altscreen feature
                termcapinfo * ti=:te=
                # windows stay after command terminates
                zombie kr

                screen -t A sh -c 'for ((i=0; i<100; i++)); do echo important info $i; done && sleep 5; ./test.sh a'

                split
                focus

                screen -t B sh -c 'for ((i=0; i<100; i++)); do echo another important info $i; done && sleep 2; ./test.sh a'





                share|improve this answer












                There's no good solution for a split screen region being cleared: zombie windows prevent screen from exiting. I had to add additional synchronization between the windows and the caller script and when they all die, I call screen -X quit explicitly.



                The altscreen command had nothing to do with this. The cursor didn't move to the bottom, because my default /etc/screenrc was half-working: the host terminal altscreen feature was used, but the altscreen wasn't cleared before switching back. To make it work by default I copied /etc/screenrc from CentOS 7 and for my case I disabled the feature completely with termcapinfo * ti=:te=.



                test.sh:



                #!/bin/bash

                # set -e

                if [ "a" = "$1" ]; then
                # decrement file name towards zero, then kill screen
                set -e
                a=-1
                cd "$COUNTERDIR"

                while true; do
                for old in *; do
                new=$((old + a))
                done
                [ 0 -eq "$a" ] || 2>/dev/null mv ./$old ./$new && break
                done

                if [ 0 -eq "$new" ]; then
                screen -X quit
                fi
                exit
                fi


                NWINDOWS=2
                COUNTERDIR=`mktemp -d`
                touch "$COUNTERDIR/$NWINDOWS"

                export COUNTERDIR

                screen -c test.screen
                rm -rf "$COUNTERDIR"


                test.screen:



                # do not use host terminal altscreen feature
                termcapinfo * ti=:te=
                # windows stay after command terminates
                zombie kr

                screen -t A sh -c 'for ((i=0; i<100; i++)); do echo important info $i; done && sleep 5; ./test.sh a'

                split
                focus

                screen -t B sh -c 'for ((i=0; i<100; i++)); do echo another important info $i; done && sleep 2; ./test.sh a'






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 21 '17 at 7:16









                basin

                6881721




                6881721



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398093%2fdo-not-clear-a-split-screen-region-when-one-command-completes%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    5C Z4mrxNXPyjAsug2 U6sQgzIb8uPv6EsZt8 ArHr2oNOvfS,5amkf5C,WBjVLt5k nCw5Q5uKboTrafY2V YL7YJ
                    QTMMvpJ,bUNqCr,RrHtFKt ceGd11sL47s,j,Go,ozf,80fu,yMkeAwH,At,K7B o0otJVBAk eHBu,L,2P1,ZBezdcIGk2o2,nC

                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    How many registers does an x86_64 CPU actually have?

                    Displaying single band from multi-band raster using QGIS