in reply to Running a CGI script from a command line?

Using the debugging feature you can write

#!/usr/bin/perl -- use strict; use warnings; use Capture::Tiny qw/ capture /; ... #~ my @cmd = ( $^X , 'foo.cgi', qw/ a=A b=B c=C/ ); my @cmd = ( $^X , 'foo.cgi', CGI->new->self_url ); my( $stdout, $stderr, $exit ) = capture { system { $cmd[0] } @cmd; };;

Capture::Tiny for avoiding the shell

Other ways are are shown in the tests, https://metacpan.org/source/LEEJO/CGI-4.20/t/form.t

Other ways are CGI::Test, CGI::Compile/CGI::Emulate::PSGI, Dancer::Plugin::FakeCGI ...

Replies are listed 'Best First'.
Re^2: Running a CGI script from a command line?
by Your Mother (Archbishop) on Jun 16, 2015 at 03:35 UTC

    A fun approach; maybe overkill here. It’s multi-arg system that avoids the shell, not capture.

      Unsure of protocol, but this is just a first ACK. The 1st reply was included in my early experiments, but I tested it again. The 3rd reply looks promising, but I'm working from the 2nd reply now... My ignorance remains profound, but I suspect I can clap the third hand.
        Just a second ACK. From studying the debugging docs in the 2nd reply, it appears that I was doing the correct thing, and yet it does not work. From running with the -w parameter I found a trivial mistake to fix. From running with the -d parameter, I received the mixed blessing of reams of unknown data. Time for meditation.

      A fun approach; maybe overkill here. It’s multi-arg system that avoids the shell, not capture.

      Well sure :) but if you don't capture it, it just goes into the regular place, at which point, the question becomes, why not do a redirect instead?

      Oh right, the OP didn't ask that exactly, that was just the question that brought me to this question (from a cgi execute another cgi) ... looked close enough :)

        I am doing some sort of redirect, in that the HTML output of the original PERL file is properly captured into a file that I can then load in a browser.

        I think I am skipping over some extremely low level of ignorance here. The answer is doubtless "intuitively obvious to the most casual observer", but I am evidently too tense?