perl-cgi Command-line debugging

Source: Internet
Author: User
Tags perl debugger



Source:



Http://www.cnblogs.com/itech/archive/2012/09/23/2698838.html






Reference:
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






In general, we can use the following methods to check CGI script errors:
1) Use-CWT to check the syntax of the CGI script, warning. For example PERL-WCT your.cgi.
2) Execute cgi:./calendar.cgi month=jan year=2001 on the command line.



3) in the command line execution, you can interactively offline input CGI parameters, the CGI script needs to add the-debug parameter use CGI QW (-debug), and then execute./calendar and input Month=jan year=2001, Finally exit the input execution (use ctrl-d on Unix or Mac; use ctrl-z on Windows).
4) put the CGI in webserver and test it with WebBrowser, you can use print to print the value of the variable to HTML to help Debug. Use Cgi::carp QW (Warningstobrowser fatalstobrowser) can also be used, and warnings and errors are printed to HTML.
5) Check the webserver log:tail-f/usr/local/apache/logs/error_log.









Two command-line instances of executing CGI scripts



1)



To invoke the CGI script by post:


$ echo -n ‘a=b;c=d‘ | REQUEST_METHOD=POST CONTENT_LENGTH=999 perl index.cgi


To invoke a CGI script by a Get method:





$ perl index.cgi ‘a=b;c=d‘








2)



For example, with the following program (notice of the-debugarguments touse CGI)


#! /usr/bin/perl

use warnings;
use strict;

use CGI qw/ :standard -debug /;

print "Content-type: text/plain\n\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 does 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)



Set environment variable query_string (instance on Windows) when get mode is used





Set [email Protected]&fullname=m+name
Perl-w scriptname.cgi





When a post is used, the contents of the query_string need to be entered into the temporary file Testinput.txt, for example





echo [Email protected]&fullname=m+name >testinput.txt

Perl-w scriptname.cgi < Testinput.txt








Help for the three Perl CGI man page



If you is 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 has to worry about tricking your script into Reading from environment variables). 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 the feature, use the-no_debug pragma.



To test the POST method, you may enable full debugging with The-debug pragma. This would allow you to feed newline-delimited name=value pairs to the script in standard input.



When debugging, you can use quotes and backslashes to escape characters in the familiar shell manner, letting your place SP Aces 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






perl-cgi Command-line debugging


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.