Perl-cgi Command Line Debugging

Source: Internet
Author: User
Tags perl debugger










Refer:

Http://docstore.mik.ua/orelly/linux/cgi/ch15_03.htm






Http://stackoverflow.com/questions/2224158/how-can-i-send-post-and-get-data-to-a-perl-cgi-script-via-the-command-line

Http://search.cpan.org /~ LDS/cgi. pm-3.20/cgi. PM # debugging












Generally, we can use the following methods to check CGI script errors:

1) Use-CWT to check CGI script syntax and warn. For example, Perl-WCT your. cgi.

2) execute CGI:./calendar. cgi month = Jan year = 2001 on the command line.






3) During command line execution, you can enter the parameters required by CGI in interactive offline mode. In this case, add the-Debug parameter use cgi qw (-Debug) to the CGI script and execute the command. /Calendar, enter month = Jan year = 2001, and exit the command (use ctrl-D on Unix or Mac; use ctrl-Z on Windows ).

4) Place CGI to webserver and test it through webbrowser. Print can be used to print the variable value to HTML for debugging. You can also use CGI: carp QW (warningstobrowser fatalstobrowser) to print warnings and errors to HTML.

5) Check the webserver log: tail-F/usr/local/Apache/logs/error_log.


















Example of the CGI script executed by the command line






1)






Use the POST method to call the CGI script:




$ Echo  -  N  'A = B; C = d'   | Request_method  =  Post content_length  =  999  Perl Index  . CGI  



Use the get method to call the CGI script:










$ Perl Index.CGI'A = B; C = d'















2)






for example, with the following Program (Notice-DebugIn the arguments touse CGI)




#! /Usr/bin/perl     Use  Warnings  ;    Use  Strict  ;     Use  CGI QW  /  :  Standard  -  Debug  /;     Print  "Content-Type: text/plain \ n"  ,   Map  {  $ _  .  "=>"   .  Param  (  $ _  )   .  "\ N"   }   Param  ;    



You feed it parameters on the command line:






$./Prog. cgi Foo = bar Baz = quux Content-Type: text/plain Foo => bar Baz => quux




You can also do so via the standard input:






$./Prog. cgi (offline mode: Enter name = value pairs on standard input; press ^ d or ^ Z when done) Foo = bar Baz = quux ^ d

Content-Type: text/plain Foo => bar Baz => quux












3)






When get is used, set the environment variableQUERY_STRING (the instance is on Windows)






Set QUERY_STRING = recipient = John@ Doe. Com & fullname = m + name

Perl-W scriptname. cgi












When post is used, the content of query_stringis input to the local file testinput.txt, for example






Echo recipient = John@ Doe. Com & fullname = m + name> testinput.txt






Perl-W scriptname. cgi <testinput.txt


















3. Help From perl cgi man page






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




To turn off this feature, use the-no_debug Pragma.






To test the POST method, you may enable full debugging with the-Debug Pragma. This will allow you to feed newline-delimited name = value pairs to the script on standard input.






When debugging, you can use quotes and backslashes to escape characters in the familiar shell manner, leader you place spaces and other funny characters in your parameter = value pairs:






Your_script.pl "name1 = 'I am a long value'" "name2 = two \ words"




Finally, you can set the path info for the script by prefixing the first name/value parameter with the path followed by a question mark (?) :






Your_script.pl/Your/path/here? Name1 = value1 & name2 = value2


















Complete!
















Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.