Find the answer to your Linux question:
Results 1 to 6 of 6
Hello, everyone, I am writing a console program in Linux. It is necessary for this program to kill the terminal after every run. However, I would like to have the ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3

    save the terminal screen

    Hello, everyone,

    I am writing a console program in Linux. It is necessary for this program to kill the terminal after every run. However, I would like to have the message on the terminal recorded in a file (only the information just before the end of the program is needed).

    How can I do that with some bash command, or program code (I use C)?

    Thank you in advance.

    Sincerely yours
    Ming

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Well, there are two options.

    The simplest one would be to just output the necessary information at the end of the program to a file instead of to the terminal. This is fairly trivial.

    A slightly more complex way would be to launch the program as follows:
    Code:
    my_program | tee program_log
    The "tee" program writes all input to both stdout and each file that it is given. Therefore, this approach would duplicate all of the program's output to the terminal and to the file "program_log".
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3

    Smile

    Thank you Cabhan.

    Your recommendations are really helpful. However, my problem is a little tricky here.

    I made my program to autostart after booting using

    Exec = xfc4-terminal --working-directory = /path/to/file ./file

    When the program is ended unexpectedly, the terminal is ended with it, and I lost all the debug information on the screen. Because there are quite a lot of output and debug information, a log file for all of them is not a practical option since I do not have space to save it. Unfortunately, I do not know where the problem is, so I can not decide where the program will end.

    Above is the reason that I am looking for a solution to just record the output of the program just before the termination of the program.

    Sincerely yours
    Ming

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    If something abnormal is happening in the execution, why do you autorun it? Just launch the terminal, and run the program yourself. Comment out whatever portion of the code tries to kill the terminal, and check for the problem that way.
    DISTRO=Arch
    Registered Linux User #388732

  5. #5
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3

    Red face

    Thank you for the input.

    About one thing you are definitely right, I need to do more debugging.

    Thank you again.

    Sincerely yours
    Ming

  6. #6
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    In complex scripts that may or may not work but have to run unattended, I let it output debugging info from within the script itself.

    Code:
    for i in list ; do
         complex stuff && echo "it worked" >> /path/to/debuglog || echo "it didnt work" >> /path/to/debuglog
    done
    --or--

    Code:
    if [ test $VAR ] ; then # test nr 1
         echo "test nr 1 passed, var is $VAR" >> /path/to/debuglog
    if [ test ] ; then # test nr 2
         echo "test nr 2 passed, var is $VAR" >> /path/to/debuglog
    else
         echo "test 1 and 2 failed, var is $VAR" >> /path/to/debuglog
    fi
    Can't tell an OS by it's GUI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...