in reply to Re: perl - bash script problem
in thread perl - bash script problem

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

Replies are listed 'Best First'.
Re^3: perl - bash script problem
by tachyon-II (Chaplain) on Nov 29, 2007 at 06:15 UTC

    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!
Re^3: perl - bash script problem
by graff (Chancellor) on Nov 30, 2007 at 02:51 UTC
    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 ..." )'