Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

backtick ignores parameters

by unclepliny (Initiate)
on May 20, 2002 at 18:58 UTC ( [id://167909]=perlquestion: print w/replies, xml ) Need Help??

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

For various pragmatic reasons (I don't want to write calendar software scratch) I am invoking a Perl app from within my own Perl code, via the backtick operator:
    $cal_output = qx/webcal.cgi DisplayMonthViewAction=on date=2002-06-24/;
This exact command, when typed at my c:\> or %> prompts, returns the correct output: month view for June.
However, when invoked via qx or ``, the output is the default view as defined in webcal.cgi (current month, May).

In other words, the name/value paramters seem to get ignored by Perl's backtick operator. You can see an example here:

http://www.hopecancer.org/cgi-bin/site/hcm.cgi?happenings_calendar=

Since this works from the commandline, I don't think that I am dealing with a bug in the script I am invoking. Any suggestions as to where I am losing the name=value params?

Much appreciated,
Pliny.

Replies are listed 'Best First'.
Re: backtick ignores parameters
by perlplexer (Hermit) on May 20, 2002 at 19:29 UTC
    Is webcal.cgi truly a CGI script? The problem is that in case of qx// or backticks, the script gets its parameters via @ARGV, and not through $ENV{QUERY_STRING} or STDIN with $ENV{CONTENT_LENGTH}.

    Are you using CGI.pm to get parameters? If so, the script shouldn't have any problems parsing @ARGV.
    The following works with ActivePerl
    ---------------cut foo.pl ------------------- use CGI; my $q = new CGI; print "$_=",$q->param($_),"\n" for $q->param; ---------------cut foo.pl ------------------- C:\Perl>perl -e "print qx/foo.pl foo=bar bar=foo/;" foo=bar bar=foo C:\Perl>
    --perlplexer
      > Is webcal.cgi truly a CGI script?

      It is -- one of the free offerings from eXtropia/Selena Sol. http://www.extropia.com/applications/webcal_perl.html

      As far as I can tell webcal.cgi is not using CGI.pm. Extropia have a whole Charlie Foxtrot, I mean, um, suite of their own event-handling modules that has been developed over 8-9 years, so the level of abstraction is pretty high.

Re: backtick ignores parameters
by Jenda (Abbot) on May 20, 2002 at 22:13 UTC

    Since the webcal.cgi is called form a CGI script it thinks it is called as a CGI itself. If it takes the parameters from @ARGV if you execute it from the prompt you migh try to delete $ENV{QUERY_STRING} and $ENV{REQUEST_METHOD} before calling the webcal.cgi. Then it will most probably work.

    Another thingie ... you've mentioned Selena Sol as the author of the webcal.cgi. I seem to remember some very bad reviews of her scripts. Actually anything that doesn't use CGI or CGI::Lite (or somesuch module), but contains a CGI parameter parsing code is suspicious.

      Jenda

    == Jenda@Krynicky.cz == http://Jenda.Krynicky.cz ==
    Always code as if the guy who ends up maintaining your code
    will be a violent psychopath who knows where you live.
          -- Rick Osborne, osborne@gateway.grumman.com
Re: backtick ignores parameters
by krujos (Curate) on May 20, 2002 at 19:03 UTC
    OTMH, dont you need to give it %20 instead of a space between the params?
      These are not URL-encoded parameters -- i am invoking the program internally, so the command gets sent to the webserver OS.
        A, Sorry if this sounds mean, I dont intend to be, but did you try it?
        B, I went back and checked out some old scripts. I had this problem as well a long time ago. I ended up using a question mark to between the params and that worked. I am not sure why exactly (darn this getting old thing). If any monks have some insight to the question mark thing I would be grateful.
        let this be a lesson to me to comment code better.

        update changed formatting...
        also, when you run things from the command line, the shell translates it first. I dont think it works the same way from inside the script. Agian please correct me if I am wrong.
        Thanks Josh
Re: backtick ignores parameters
by broquaint (Abbot) on May 20, 2002 at 19:33 UTC
    That really should work as you describe ... Perhaps you could post the offending code which would make it infinitely easier for fellow monks to debug. Also, if you want to save yourself the trouble of having to call external scripts you could make use of the HTML::CalendarMonth module or simpler still the HTML::Calendar::Simple module.
    HTH

    _________
    broquaint

      There is 1.2MB of offending code (all Perl, yup). If you really want at it (you don't): http://www.extropia.com/applications/downloads/webcal_perl.html?

      I was seriously hoping that i was invoking qx// improperly, since webcal.cgi parses the params fine when I type them at the prompt.

      Re: the modules you referenced, I'm sure they will work fine and I'll use them if I need to. The goal here is content management for non-programmers, so I chose WebCal for having an admin interface et al in place already. No need to re-invent the wheel, as it were.

      I'll wade through webcal.cgi some more.

      Thanks for the replies all,


      Pliny.
Got It
by unclepliny (Initiate) on May 20, 2002 at 21:43 UTC
    This is odd. Apparently webcal.cgi, the script that I am backtick-invoking from within my own Perl script hcm.cgi, is reading the parameters passed to hcm.cgi, not the parameters sent to webcal.cgi via qx//.

    Go figure. It makes sense in some vague fuzzy way, but I have to marinate on that one. At any rate I can work with it.

    Thx again for the replies,


    Pliny

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://167909]
Approved by particle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2024-03-28 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found