carol has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to log what happens in the CPAN shell? Sometimes, when installing a bundle and something bad happens, I can not scroll back far enough. Therefore I can not go back to the first point where problems occurred. I tried cpan | tee -a mylog.txt, but the shell does not behave nicely with tee: the prompt does not appear after a command and the cursor ends up in peculiar places.

Update: Thank you all for pointing me to script. I realise I want logging often when learning new things (in this case the CPAN shell). In my search I also discovered two other possibilities, although script remains the best and simplest:

  1. CPANPLUS has a write_install_log configuration parameter.
  2. File::Tee can do it if one doesn't mind missing STDIN in the log. Edit (a copy of) the cpan script and put the following somewhere at the top:
    use File::Tee; tee STDOUT, { prefix => 'OUT: ', lock => 1, mode => '>>', open => '/tmp/log.txt' }; tee STDERR, { prefix => 'ERR: ', lock => 1, mode => '>>', open => '/tmp/log.txt' };

Replies are listed 'Best First'.
Re: Logging the CPAN Shell
by marto (Cardinal) on May 11, 2008 at 13:28 UTC
    you could try something like:
    >script $HOME/cpan.log Script started, file is cpan.log >cpan install Net::FTP .....
    To stop logging type 'exit' at the command prompt, you should see something like <code>Script done, file is cpan.log. Perhaps there is a 'smarter' way to achieve this, but I think this should work for you.

    Hope this helps

    Martin
Re: Logging the CPAN Shell
by quester (Vicar) on May 11, 2008 at 21:22 UTC

    As marto mentioned, script handles prompting better than tee. However, you will still have escape sequences cluttering up your log. To get rid of them, set the environment variable TERM to "dumb", which works for most character-based programs that send escape sequences.

    For example:

    script -c 'TERM=dumb cpan' -a mylog.txt
    If you used the backspace key to make corrections and need to remove the backspaces and the erased characters from the log, try this:
    perl -i.bak -wpe '1 while s/[^\x08]\x08//' mylog.txt
Re: Logging the CPAN Shell
by planetscape (Chancellor) on May 12, 2008 at 00:51 UTC

    I generally do something like:

    make test > test.txt 2>&1

    which I got from jacques' homenode.

    (Works for me on Win32 and Cygwin.)

    HTH,

    planetscape