Mar 16

How to feed query string values to a script on command line

Category: Linux,Perl   — Published by tengo on March 16, 2009 at 8:03 am

Often while debugging nasty "500 Internal Server Errors" and when everything seems to work on command line but the webserver refuses to properly serve your script's output (btw: check if you set permissions right, twice!) you might want to feed the query_string to a script on command line. Running a script in default mode, without passed parameters (which running on CLI essentially is) in certain scenarious might work while the same script chokes on runmodes it enters through passed variables.

To simulate what a server will do while invoking your script it may appear natural to just do:

> perl

but this will fail. On devshed you can read that "The shell uses whitespace to delimit commandline tokens. [Such syntax] is great if the parent process is a web server. Replace your delimiters '?' and '&' with whitespace. The perl script will then see the discrete arguments, as well." So alter your command like this:

> perl rm=test var=value

and voila, your script will execute as if you passed these query string values via URL.