in reply to Re: Newbie Question
in thread Newbie Question

English is not my first language, so I am having some trouble explaining what I want to do. :o)
You are correct in your assumption that 1.pl is usually call via a browser using:
http://www.server.com/cgi-bin/1.pl?filename.txt
But it is not the filename.txt I want.
I want the result of the above url/execution written to a file, using a second script, 2.pl

Replies are listed 'Best First'.
RE: RE: Re: Newbie Question
by Fastolfe (Vicar) on Oct 25, 2000 at 19:27 UTC
    The feasibility of this depends totally on the nature of the CGI script you're wanting to call by hand. CGI scripts by their nature expect to be called from a web server, expect their arguments to provided per CGI spec, and will provide CGI output. The script.pl?argument construct is a web/CGI thing, but since you're trying to call your script via standard system() methods, CGI methods don't apply. Fortunately, the "GET" method you're using makes it easy:
    system("./1.pl filename.txt"); # to stdout, or: my $output = `./1.pl filename.txt` # in $output
    A security note: If, instead of using "filename.txt", you use a user-provided variable, make SURE your script uses taint-checking (-T argument, see perlsec) and un-taint the variable smartly before attempting to use it, or someone can easily put in a filename of "/etc/passwd" or "some.file;rm -rf /etc/httpd|", for example.

    Since the script is a CGI script, its output will contain CGI headers. If this is OK, great. Otherwise, you will need to strip them out.

    Perhaps you should consider an ASP technique for running a CGI script "within" the context of a page (with SSI this is called a "virtual include").

    Hope this helps.

RE: RE: Re: Newbie Question
by wardk (Deacon) on Oct 25, 2000 at 21:04 UTC

    My intent was to quickly show how to get the passed parameter easily using perl's CGI.pm module (since you indicated your experience was with ASP). Wasn't attempting to address what would be done with the data.

    Seems that your 2.pl could use LWP to call the above file, storing the results in a variable/array.

    or you could execute 1.pl from the command line using CGI.pm

    perl 1.pl file=filename.txt > outfile

    which could also be done via a 2.pl program, shell script or .bat file.

    Hope these bits and pieces are helpful