Watching something be piped to a file live with tailHow to continue running a program inspite of killing the shell which invoked itLinux terminal, my program only resumes after scrolling the printoutIs there a command in Linux which waits till it will be terminated?Ctrl+c in a sub process is killing a nohup'ed process earlier in the scriptCtrl-C'd an in-place recursive gzip - is this likely to have broken anything?Getting output of another script while preserving line-breakssocat and rich terminal againScript executed as other user from root creates files in wrong directory (root)Dealing with Ctrl+Z in UnixHow to pass Ctrl+C to script called from batch job

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Can we compute the area of a quadrilateral with one right angle when we only know the lengths of any three sides?

Is it possible to create a QR code using text?

CAST throwing error when run in stored procedure but not when run as raw query

How do conventional missiles fly?

I would say: "You are another teacher", but she is a woman and I am a man

Why can't we play rap on piano?

iPad being using in wall mount battery swollen

Should I tell management that I intend to leave due to bad software development practices?

How could indestructible materials be used in power generation?

Arrow those variables!

Mathematica command that allows it to read my intentions

Can compressed videos be decoded back to their uncompresed original format?

How much of data wrangling is a data scientist's job?

Why do bosons tend to occupy the same state?

Why no variance term in Bayesian logistic regression?

What method can I use to design a dungeon difficult enough that the PCs can't make it through without killing them?

Bullying boss launched a smear campaign and made me unemployable

Can a virus destroy the BIOS of a modern computer?

Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?

How did the Super Star Destroyer Executor get destroyed exactly?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Can I run a new neutral wire to repair a broken circuit?

Examples of smooth manifolds admitting inbetween one and a continuum of complex structures



Watching something be piped to a file live with tail


How to continue running a program inspite of killing the shell which invoked itLinux terminal, my program only resumes after scrolling the printoutIs there a command in Linux which waits till it will be terminated?Ctrl+c in a sub process is killing a nohup'ed process earlier in the scriptCtrl-C'd an in-place recursive gzip - is this likely to have broken anything?Getting output of another script while preserving line-breakssocat and rich terminal againScript executed as other user from root creates files in wrong directory (root)Dealing with Ctrl+Z in UnixHow to pass Ctrl+C to script called from batch job













2















I have a python program which is, slowly, generating some output.



I want to capture that in a file, but I also thought I could watch it live with tail.



So in one terminal I'm doing :



python myprog.py > output.txt


and in another terminal :



tail -f output.txt


But it seems like the tail isn't showing me anything while the python program is running. If I hit ctrl-c to kill the python script, suddenly the tail of output.txt starts filling up. But not while the python is running.



What am I doing wrong?










share|improve this question

















  • 2





    How about python myprog.py | tee output.txt instead?

    – n8te
    3 hours ago











  • @n8te tee might show the same problem if the program isn't flushing the output buffer regularly. This needs flush() and tee.

    – JPhi1618
    46 mins ago











  • @JPhi1618 - you could be right but I just tested it with 800MB of data output and it didn't skip a beat.

    – n8te
    33 mins ago















2















I have a python program which is, slowly, generating some output.



I want to capture that in a file, but I also thought I could watch it live with tail.



So in one terminal I'm doing :



python myprog.py > output.txt


and in another terminal :



tail -f output.txt


But it seems like the tail isn't showing me anything while the python program is running. If I hit ctrl-c to kill the python script, suddenly the tail of output.txt starts filling up. But not while the python is running.



What am I doing wrong?










share|improve this question

















  • 2





    How about python myprog.py | tee output.txt instead?

    – n8te
    3 hours ago











  • @n8te tee might show the same problem if the program isn't flushing the output buffer regularly. This needs flush() and tee.

    – JPhi1618
    46 mins ago











  • @JPhi1618 - you could be right but I just tested it with 800MB of data output and it didn't skip a beat.

    – n8te
    33 mins ago













2












2








2








I have a python program which is, slowly, generating some output.



I want to capture that in a file, but I also thought I could watch it live with tail.



So in one terminal I'm doing :



python myprog.py > output.txt


and in another terminal :



tail -f output.txt


But it seems like the tail isn't showing me anything while the python program is running. If I hit ctrl-c to kill the python script, suddenly the tail of output.txt starts filling up. But not while the python is running.



What am I doing wrong?










share|improve this question














I have a python program which is, slowly, generating some output.



I want to capture that in a file, but I also thought I could watch it live with tail.



So in one terminal I'm doing :



python myprog.py > output.txt


and in another terminal :



tail -f output.txt


But it seems like the tail isn't showing me anything while the python program is running. If I hit ctrl-c to kill the python script, suddenly the tail of output.txt starts filling up. But not while the python is running.



What am I doing wrong?







linux command-line pipe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









interstarinterstar

320311




320311







  • 2





    How about python myprog.py | tee output.txt instead?

    – n8te
    3 hours ago











  • @n8te tee might show the same problem if the program isn't flushing the output buffer regularly. This needs flush() and tee.

    – JPhi1618
    46 mins ago











  • @JPhi1618 - you could be right but I just tested it with 800MB of data output and it didn't skip a beat.

    – n8te
    33 mins ago












  • 2





    How about python myprog.py | tee output.txt instead?

    – n8te
    3 hours ago











  • @n8te tee might show the same problem if the program isn't flushing the output buffer regularly. This needs flush() and tee.

    – JPhi1618
    46 mins ago











  • @JPhi1618 - you could be right but I just tested it with 800MB of data output and it didn't skip a beat.

    – n8te
    33 mins ago







2




2





How about python myprog.py | tee output.txt instead?

– n8te
3 hours ago





How about python myprog.py | tee output.txt instead?

– n8te
3 hours ago













@n8te tee might show the same problem if the program isn't flushing the output buffer regularly. This needs flush() and tee.

– JPhi1618
46 mins ago





@n8te tee might show the same problem if the program isn't flushing the output buffer regularly. This needs flush() and tee.

– JPhi1618
46 mins ago













@JPhi1618 - you could be right but I just tested it with 800MB of data output and it didn't skip a beat.

– n8te
33 mins ago





@JPhi1618 - you could be right but I just tested it with 800MB of data output and it didn't skip a beat.

– n8te
33 mins ago










2 Answers
2






active

oldest

votes


















3














You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.



import sys
...
print('Some message')
sys.stdout.flush()






share|improve this answer








New contributor




Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    3














    Instead of trying to tail a live file, use tee instead. It was made to do exactly what you're trying to do.



    From man tee:




    tee(1) - Linux man page



    Name tee - read from standard input and write to standard output and files



    Synopsis



    tee [OPTION]... [FILE]...


    Description



    Copy standard input to each FILE, and also to standard output.



    -a, --append 
    append to the given FILEs, do not overwrite
    -i, --ignore-interrupts
    ignore interrupt signals
    --help
    display this help and exit
    --version
    output version information and exit


    If a FILE is -, copy again to standard output.




    So in your case you'd run:



    python myprog.py | tee output.txt





    share|improve this answer























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "3"
      ;
      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1421123%2fwatching-something-be-piped-to-a-file-live-with-tail%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      3














      You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.



      import sys
      ...
      print('Some message')
      sys.stdout.flush()






      share|improve this answer








      New contributor




      Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























        3














        You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.



        import sys
        ...
        print('Some message')
        sys.stdout.flush()






        share|improve this answer








        New contributor




        Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






















          3












          3








          3







          You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.



          import sys
          ...
          print('Some message')
          sys.stdout.flush()






          share|improve this answer








          New contributor




          Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.










          You may also need to explicitly flush the buffer for it to get piped upon generation. This is because output is typically only printed when the pipe's buffer fills up (which is in kilobytes I belive), and when the stdin message ends. This is probably to save on read/writes. You could do this after every print, or if you are looping, after the last print within the loop.



          import sys
          ...
          print('Some message')
          sys.stdout.flush()







          share|improve this answer








          New contributor




          Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 3 hours ago









          DaveyDavey

          461




          461




          New contributor




          Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Davey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.























              3














              Instead of trying to tail a live file, use tee instead. It was made to do exactly what you're trying to do.



              From man tee:




              tee(1) - Linux man page



              Name tee - read from standard input and write to standard output and files



              Synopsis



              tee [OPTION]... [FILE]...


              Description



              Copy standard input to each FILE, and also to standard output.



              -a, --append 
              append to the given FILEs, do not overwrite
              -i, --ignore-interrupts
              ignore interrupt signals
              --help
              display this help and exit
              --version
              output version information and exit


              If a FILE is -, copy again to standard output.




              So in your case you'd run:



              python myprog.py | tee output.txt





              share|improve this answer



























                3














                Instead of trying to tail a live file, use tee instead. It was made to do exactly what you're trying to do.



                From man tee:




                tee(1) - Linux man page



                Name tee - read from standard input and write to standard output and files



                Synopsis



                tee [OPTION]... [FILE]...


                Description



                Copy standard input to each FILE, and also to standard output.



                -a, --append 
                append to the given FILEs, do not overwrite
                -i, --ignore-interrupts
                ignore interrupt signals
                --help
                display this help and exit
                --version
                output version information and exit


                If a FILE is -, copy again to standard output.




                So in your case you'd run:



                python myprog.py | tee output.txt





                share|improve this answer

























                  3












                  3








                  3







                  Instead of trying to tail a live file, use tee instead. It was made to do exactly what you're trying to do.



                  From man tee:




                  tee(1) - Linux man page



                  Name tee - read from standard input and write to standard output and files



                  Synopsis



                  tee [OPTION]... [FILE]...


                  Description



                  Copy standard input to each FILE, and also to standard output.



                  -a, --append 
                  append to the given FILEs, do not overwrite
                  -i, --ignore-interrupts
                  ignore interrupt signals
                  --help
                  display this help and exit
                  --version
                  output version information and exit


                  If a FILE is -, copy again to standard output.




                  So in your case you'd run:



                  python myprog.py | tee output.txt





                  share|improve this answer













                  Instead of trying to tail a live file, use tee instead. It was made to do exactly what you're trying to do.



                  From man tee:




                  tee(1) - Linux man page



                  Name tee - read from standard input and write to standard output and files



                  Synopsis



                  tee [OPTION]... [FILE]...


                  Description



                  Copy standard input to each FILE, and also to standard output.



                  -a, --append 
                  append to the given FILEs, do not overwrite
                  -i, --ignore-interrupts
                  ignore interrupt signals
                  --help
                  display this help and exit
                  --version
                  output version information and exit


                  If a FILE is -, copy again to standard output.




                  So in your case you'd run:



                  python myprog.py | tee output.txt






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 3 hours ago









                  n8ten8te

                  5,17272234




                  5,17272234



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1421123%2fwatching-something-be-piped-to-a-file-live-with-tail%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Möglingen Índice Localización Historia Demografía Referencias Enlaces externos Menú de navegación48°53′18″N 9°07′45″E / 48.888333333333, 9.129166666666748°53′18″N 9°07′45″E / 48.888333333333, 9.1291666666667Sitio web oficial Mapa de Möglingen«Gemeinden in Deutschland nach Fläche, Bevölkerung und Postleitzahl am 30.09.2016»Möglingen

                      Virtualbox - Configuration error: Querying “UUID” failed (VERR_CFGM_VALUE_NOT_FOUND)“VERR_SUPLIB_WORLD_WRITABLE” error when trying to installing OS in virtualboxVirtual Box Kernel errorFailed to open a seesion for the virtual machineFailed to open a session for the virtual machineUbuntu 14.04 LTS Virtualbox errorcan't use VM VirtualBoxusing virtualboxI can't run Linux-64 Bit on VirtualBoxUnable to insert the virtual optical disk (VBoxguestaddition) in virtual machine for ubuntu server in win 10VirtuaBox in Ubuntu 18.04 Issues with Win10.ISO Installation

                      Antonio De Lisio Carrera Referencias Menú de navegación«Caracas: evolución relacional multipleja»«Cuando los gobiernos subestiman a las localidades: L a Iniciativa para la Integración de la Infraestructura Regional Suramericana (IIRSA) en la frontera Colombo-Venezolana»«Maestría en Planificación Integral del Ambiente»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»«Conózcanos»«Caracas: evolución relacional multipleja»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»