to generate the output in a log file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rahul83
    New Member
    • Jul 2007
    • 2

    to generate the output in a log file

    Hi.. I have written a perl script for displaying the difference between two directory structures.(inc luding the diffferences in the files)
    I have to generate the output in a log file.

    [CODE=perl]
    #!usr/local/bin/perl -w
    use Test::More tests => 5;
    use Test::Files;
    use File::Spec;

    my $logging = "file";

    if ($logging eq "file") {
    open LOG, ">output.lo g" or die $!;
    select LOG;
    }

    print "\nEnter the first folder name\n";
    my $dir1 = <STDIN>;
    chomp($dir1);

    print "\nEnter the second folder name\n";
    my $dir2 = <STDIN>;
    chomp($dir2);

    compare_dirs_ok ($dir1,$dir2,"R EPORT1");
    compare_dirs_ok ($dir2,$dir1,"R EPORT2");

    select STDOUT;
    [/CODE]

    I have tried changing the FileHandle to LOG file. But its not working in the function compare_dirs_ok ()
    can any1 suggest something for generating the output in a log file instead of standard output.
    Last edited by miller; Jul 12 '07, 03:08 PM. Reason: Code Tag and ReFormatting
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    I am going to assume that you are running this on a Unix system since your shebang references a Unix based path. Not to bypass a coded solution, but have you tried setting your standard out and standard error to a log file as you execute the script?

    ie:
    Code:
           /path/to/perl/script.pl   >output.log  2>&1
    This will execute your script and send standard output to "output.log ". In addition, it will take standard error(2) and output it to the same place as standard out (1). If you want the errors to go someplace else, then replace the "&1" with the path to the errors log file.

    Regards,

    Jeff
    Last edited by numberwhun; Jul 12 '07, 12:51 PM. Reason: Add code tags

    Comment

    Working...