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

Okay folks, I decided to come here and try my luck at getting a direct answer to the problems i've been having since i've already wasted way too much time waiting for a good answer to my questions at a Microsoft forum. Here's my problem: I wrote an ASP page based off some code an "expert" gave me at the microsoft site that is supposed to execute a PERL script server-side through the use of WSH. THe problem is that the PERL script is supposed to output two files and these files are not showing up on the server. I'm figuring my paths arent set up right and such but i dont know what to do to fix it. The ASP file, PERL script, and file used by the script are all located in the same directory ( my web home directory). ActivePERL is installed on the server, and i can execute the PERL script directly and receive correct results. Does anyone know what i need to do to the code provided below to fix my problems? Not sure if i've provided all the needed info but i'm new to Microsoft programming (I'm a C programmer by trade...and VBS just isnt my thing..) Any help would be of great appreciation. thanks. HTML:
<html> <body> <form method=post> <input name=text1><br> <input type=submit value=submit id=submit1 name=submit1> </form> <% dim user dim wshell user=trim(request.form("text1")) if len(user) > 0 then response.write "<hr>user: " &amp; user set wshell = createobject("wscript.shell") '=== ' assume script is in same folder as page... '=== sScript = server.mappath("test1.pl") '=== ' run script in hidden window... '=== wshell.run "perl """ &amp; sScript &amp; """ " &amp; user, 0, false set wshell = nothing end if %> </body> </html>
PERL:
# Variables # $quit_loop = 0; $found_name = 0; @username = @ARGV; $loop = 0; # Converting username to correct format for comparison search $username[0] = substr($username[0], 1, 4); if ( substr($username[0], 0, 1) eq "0" ) { $username[0] = substr($username[0], 1, 3); } # Cleaning up the Kronos document open(ORIGFILE,"current") || die "cannot open current for reading"; open(REVFILE,">revfile") || die "cannot open revfile for writing"; while (<ORIGFILE>) # read each line of ORIGFILE { if (/South/) # If a South Bend Line { <ORIGFILE>; <ORIGFILE>; <ORIGFILE>; } elsif (/-+/) { print REVFILE $_; <ORIGFILE>; <ORIGFILE>; } else { print REVFILE $_; } } close(ORIGFILE); close(REVFILE); # Searching for the correct username to return data to another file open(REVFILE, "revfile") || die "cannot open revfile for reading"; open(FINALFILE, ">finalfile.txt") || die "cannot open finalfile for wr +iting"; while (<REVFILE>) { # Converting Kronos username for comparison $current_line = $_; $current_id = substr($current_line, 33, 4); if ( substr($current_id, 0, 1) eq "0" ) { $current_id = substr($current_id, 1, 3); } if ( substr($current_id, 3, 1) eq " ") { $current_id = substr($current_id, 0, 3); } unless ($quit_loop == 1 ) { if ($found_name == 1) { if (/-+/) { $quit_loop = 1; } else { print FINALFILE $_; } } elsif ($current_id eq $username[0]) { $found_name = 1; print FINALFILE $_; } else { $found_name = 0; } } } $quit_loop = 0; print FINALFILE $path; close(REVFILE); close(FINALFILE);

Replies are listed 'Best First'.
Re: IIS and Perl, yippee
by !me (Acolyte) on Jul 20, 2001 at 21:49 UTC
    Do you mind if I ask why your even bothering with the ASP ? Why not just write the entire thing in perl ? Anyway.. Adding the following to the top of your perl script should do the trick.
    chdir('/my web home directory/');
      If i can do the whole thing in perl i would love it, show me the code and its a done deal. Thanks. Jason
        Alright, i lied, the error i'm getting is that it can't open revfile for writing... the thing is... the command i'm using is just to create the file and open it for writing, so of course it isnt going to find it... Doesnt PERL create a file by that name in the directory if it cant find it and open it for writing? Maybe i'm wrong...
Re: IIS and Perl, yippee
by gregorovius (Friar) on Jul 21, 2001 at 01:20 UTC
    The command you are using will create the file if it isn't there. It looks more like a permissions problem. Have you checked that the user you run IIS as has write permission on the directory where you want to write? Which directory is this? You need to add the chdir statement !me recommends.

    Also, it would be much simpler if you got rid of the VBScript and placed your perl program directly on the ASP file. Look at the Perl-Win32-ASP faq for how to do this.

      How do i access form variables that are set up to POST.. I read the FAQ and the link to a function to do this is broken... Thanks.
        You should use the CGI.pm module for that. Here's a snippet, but you should browse the CGI.pm documentation that is bundled with the Activestate Perl docs.

        Alternatively you should be able to access the form params from the request object that ASP provides automatically. I don't recall right now how to get to it, but it's surely in the Activestate docs.

        my $query = CGI->new; # save POST and GET parameters into %FORM foreach ($query->param) { $FORM{$_} = $query->param($_); }