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

Is there a way to pass a query string to a perl script from a Win32 command line so that the perl scripts functions as if it were sent post data?
  • Comment on Passing a query string from a command line (Win32)

Replies are listed 'Best First'.
Re: Passing a query string from a command line (Win32)
by davido (Cardinal) on Oct 29, 2005 at 07:40 UTC

    There is if you're using CGI.pm. From the POD for CGI:

    DEBUGGING
    If you are running the script from the command line or in the perl debugger, you can pass the script a list of keywords or parameter=value pairs on the command line or from standard input (you don't have to worry about tricking your script into reading from environment variables). You can pass keywords like this:

    your_script.pl keyword1 keyword2 keyword3

    or this:

    your_script.pl keyword1+keyword2+keyword3

    or this:

    your_script.pl name1=value1 name2=value2

    or this:

    your_script.pl name1=value1&name2=value2

    Dave

      My script does use cgi but when it is run from the command line it returns different results than if run from a browser. Is there a way to trick a script to think that is was run from a browser? How does Apache or other web servers open the script and get results? What do they do different? Aren't they reading from STDOUT also? Isn't there a way to simulate a web server to get the 'web' results of a single script?

        If you find downloading, setting up and maintaining Apache is daunting, or like me, just a pain in the artic, take a look here.

        70k to download, setup consists of 2 options and it does most of what apache does.

        Probably not good for running your multinational conglomorate, but for testing your scripts at home...


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        Hi slloyd,

        When I was in your position I installed Apache. Why try to simulate one when you can have the real thing?

        Hope that helps

Re: Passing a query string from a command line (Win32)
by jesuashok (Curate) on Oct 29, 2005 at 09:58 UTC
    Hi,



    Just to add few more points on the same.

    The above replies are applicable only to Win32 systems.



    If you run the script through command line in unix or linux :-

    your_script name1=value1 name2=value2

    Only the above syntax works fine in unix and linux Os's

    "Keep pouring your ideas"