Redirecting stdout of a program being screen'd

Discussion in 'OT Technology' started by TheDarkHorizon, Feb 14, 2004.

  1. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    I tried screen echo hi > hi and screen [ echo hi > hi ], but the file "hi" always ends up empty. Is there something I'm doing wrong? :dunno:
     
  2. Leb_CRX

    Leb_CRX OT's resident terrorist

    Joined:
    Apr 22, 2001
    Messages:
    39,994
    Likes Received:
    0
    Location:
    Ottawa, Canada
    works for me? :dunno:
     
  3. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    [[email protected] httpd-2.0.48]# screen echo hi > hi
    [screen is terminating]
    [[email protected] httpd-2.0.48]# ls -l hi
    -rw-r--r-- 1 root root 0 Feb 14 16:12 hi
    [[email protected] httpd-2.0.48]# cat hi
    [[email protected] httpd-2.0.48]#
     
  4. Rob

    Rob OT Supporter

    Joined:
    Jul 6, 2002
    Messages:
    88,612
    Likes Received:
    36
    Location:
    Atlanta, GA
    I am sure there is a command line switch in screen to log stdout to a specific file. Read the man page for it.
     
  5. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    hi comes up empty for me too. Any specific reason why you're using screen echo instead of just echo? It works fine with echo.
     
  6. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    I've been looking, but I can't find it. The closest I've found so far is logging, but from what I've read so far, I need to begin logging from the terminal, which I won't be able to do.
    I was just using it as an example. I have another program I was trying it with, but the same thing happened.
     
  7. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    If you just type "screen echo hi" it doesn't show hi in the terminal, so my guess is that that's why it's not streaming it to file properly.
     
  8. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    I can see it on my terminal, but it cuts off the first character. Screen creates a new terminal and clears the screen first, and then when it exits, it clears it again.
     
  9. TMReX

    TMReX Spoooooon!

    Joined:
    May 23, 2003
    Messages:
    50
    Likes Received:
    0
    Location:
    you better check under the sea! or Dallas
    Theoretically you can create a custom screenrc file and enable a custom log file and specify the file with the -c command line option. In my experience however, I have had trouble with the log file not being flushed quickly enough for output immediately before exit (within 1-10 seconds) which results in a slightly truncated log file. You can set the log flush interval, but only down to 1 second (as far as I know.) Your mileage may vary so you could try that approach. If the file is named "myscreenrc" then run "screen -c myscreenrc echo hi" (but using this example you should see the potential problem.)

    There is another approach which should work 100% of the time.

    When you type "screen echo hi > hi.txt", because it is the shell handling the redirection the '>' character means squat because screen isn't using the standard output methods to display what you see on your screen. Escaping the '>' also doesn't help because it is then passed by screen to the program so the program thinks it is an argument.

    What you want is to give output redirection control back to the shell, (but the shell must be running inside of the screen process) so you set up a shell script (let's assume this one is echohi.sh) and put in it:
    And then you run "screen echohi.sh" you will end up with the text you expect in the file hi.txt. Maybe not super elegant, but at least you can do the output redirection.

    Hopefully something in here helps ya out.
     
  10. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    Thanks for the explanation. I thought of creating another script to redirect stdout but wanted to steer away from all these files I'm going to have. It looks like the easiest way.
     
  11. Rob

    Rob OT Supporter

    Joined:
    Jul 6, 2002
    Messages:
    88,612
    Likes Received:
    36
    Location:
    Atlanta, GA
    :bowdown: tmrex is our new unix shell guru. :big grin:
     
  12. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    :werd:
     

Share This Page