http://qs1969.pair.com?node_id=587771

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

I'm a cgi newby trying to call a perl script from my cgi script that takes a list of file names and gets those files from Visual SourceSafe using an ant target. I tried to set the $ENV variable to include JAVA_HOME and SSDIR and when I print the contents of the environment I do see these set.

The problem is when I run the cgi script I get an error that No VSS database (srcsafe.ini) found. Use the SSDIR environment variable or run netsetup. I'm sure the path is correct but it doesn't work. Anyone else ever tried something like this?

Here is my code
my $filepath = "C:\\Source\\files.log"; open (IN, $filepath) || die "Can't open $filepath:$!"; while ( my $line = <IN> ) { chomp $line; next if ($line =~ /^\s*$/ or # blank lines $line =~ /^\s*#/); # comments push(@filesaffected, $line); } close IN; for (@filesaffected){ ($dir, $fname)= $_ =~ /^(.*?)[\\\/]([^\\\/]+)$/; chdir $builddir; $ENV{'JAVA_HOME'}="C:\\j2sdk1.4.2"; $ENV{'SSDIR'}="\\\\chinook\\Sourcesafe\\Acme"; exec "ant tate_get_loc -DLocDirName=$dir -DFileName=$fname"; }

Replies are listed 'Best First'.
Re: cgi environment
by friedo (Prior) on Dec 05, 2006 at 01:02 UTC

    I don't know what the specific problem is, but here are a few suggestions that may help you find out.

    1. Are you using strict? I notice a few variables, like $builddir, $dir and $fname that don't have a declared scope.
    2. In your for loop, you should scope $dir and $fname to the inside of the loop (with my) so you can be sure that they get re-defined each time through. Also, try printing them to STDERR (under CGI it will go to the error log) so you can make sure they are what you think they are.
    3. Check the return value from chdir. Like open, it will return false and set $! upon failure. It may be that your web server user doesn't have permission to enter the directory.
    4. Don't use all those crazy backslashes inside double-quoted-strings. They make your pathnames very confusing. Instead, use single-quoted strings, e.g.

      $ENV{'SSDIR'} = '\chinook\Sourcesafe\Acme';

    That should set you on the right track.
Re: cgi environment
by clwolfe (Scribe) on Dec 05, 2006 at 02:11 UTC

    As the previous poster suggested, running with 'use strict' and 'use warnings' will make your life much, much easier. Perl without those saftery features can be very frustrating and mysterious to the newbie. With those features turned on, Perl will check for mispelled variables, funny code constructs, and all sorts of other things that you probably didn't mean to do.

    That said one other problem is that you're calling exec within a for loop. As the handy documentation says (See perldoc -f exec), exec calls the command specified and never returns. Your process is replaced with the new process. So your for loop would execute at most once. Instead, you should probably use system or else fork and then exec. That second one is probably a bad idea, though.

Re: cgi environment
by gellyfish (Monsignor) on Dec 05, 2006 at 09:55 UTC

    Does the user that the CGI program is run as have access to the the \\chinook\Sourcesafe share?

    /J\