in reply to perl - bash script problem

We'd have to see the code you're using to try to run the bash file to give you good advice.

Replies are listed 'Best First'.
Re^2: perl - bash script problem
by megaurav2002 (Monk) on Nov 29, 2007 at 05:58 UTC
    Here is what i am doing:
    my $diffFile = "$reportsPath/DiffReport.bash"; open (DIFFBASH, ">$diffFile"); print DIFFBASH "#!/usr/local/bin/bash\n#\n"; print DIFFBASH "cd $wrPath\n"; print DIFFBASH "cvs diff >> $reportsPath/diffReport.txt"; close (DIFFBASH); chmod 0775, $diffFile; # Run the bash file system "./$diffFile";

    Thanks, Gaurav
    "Wisdom begins in wonder" - Socrates, philosopher

      You are not checking for any errors. If you had checked for errors, you would not need to ask this question, perl would have already given you the answer. The problem will almost certainly be the ./ before $diffFile and the error will be "file does not exist" as you write the file to the path $diffFile not ./$diffFile.

      $! Check your return values regularly and avoid frustration $!

        Thanks for this n your advice. Works fine!
      Now that you have it working, I wonder why you bother writing a bash script file to be executed in a separate system call, rather than just doing the "cvs" command itself via a perl system call. Seems like your script could just be:
      chdir $wrPath; my $failed = system( "cvs diff >> $reportsPath/diffReport.txt" ); if ( $failed ) { warn "cvs diff returned non-zero exit status $failed\n"; }
      If the rest of the script does stuff that depends crucially on what your current working directory is (before and/or after running "cvs diff"), you just need to add:
      use Cwd; my $origpath = getcwd; # before doing 'chdir $wrPath' ... chdir $origpath; # after doing 'system( "cvs diff ..." )'