Forum Moderators: coopster & phranque

Message Too Old, No Replies

How do I run a script with a query string, from the shell?

         

doctormelodious

10:54 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



Greetings,

I have a script thing.cgi which parses a query string and uses those values. Normally, the query string is embedded in a link on a web page. I want to run it from the command line in the shell. But I can't find any info on how to do this with a query string appended.

I tried:


perl thing.cgi?foo=bar

but I got


Can't open perl script "perl thing.cgi?foo=bar": No such file or directory

How do I do this?

Thanks!
Perry

MichaelBluejay

2:55 am on Jul 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ooh, ooh, I know this one!

Just separate your parameters with spaces, like so:


perl test.cgi var1 var2

You can refer to each piece of data as $ARGV[0], $ARGV[1], etc.

If you use the = sign to make a name/value pair then that counts as one piece of data. For example:


perl test.cgi fruit=banana error=booboo

In this case $ARGV[0] is "fruit=banana" and $ARGV[1] is "error=booboo".

I think there's a param function that splits them up for you automatically, but I always use just values in my query strings, not names and values, so I'm not really familiar with it. But I guess what you really wanted to know was how to use a query string in the shell, and the short answer is to just use spaces.

SeanW

1:41 pm on Jul 7, 2004 (gmt 0)

10+ Year Member



Use CGI.pm, it detects this automagically and will prompt you for parameters.

Sean