perl-cgi命令行调试
参考:
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
一 一般地我们可以使用以下方法来检查cgi脚本的错误:
1)使用-cwT来检查cgi脚本的语法,警告。例如perl -wcT your.cgi.
2)在命令行执行cgi:./calendar.cgi month=jan year=2001.
3)在命令行执行时可以交互式offline地输入cgi需要的参数, 此时cgi脚本中需要加入-debug参数 use CGI qw(-debug);,然后执行./calendar 且输入 month=jan year=2001,最后退出输入执行(use Ctrl-D on Unix or Mac; use Ctrl-Z on Windows) 。
4)将cgi放到webserver,然后通过webbrowser来对其测试,此时可以使用print来打印变量的值到html来帮助调试。也可以使用use CGI::Carp qw(warningsToBrowser fatalsToBrowser);将警告和错误打印到html。
5)检查webserver的log:tail -f /usr/local/apache/logs/error_log.
二 命令行执行cgi脚本的实例
1)
通过post方式来调用cgi脚本:
$ perl index.cgi 'a=b;c=d'
2)
For example, with the following program (notice -debug in the arguments to use CGI)
your_script.pl keyword1 keyword2 keyword3 or this:
your_script.pl name1=value1 name2=value2 or this:
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
完!
页:
[1]