perl-cgi命令行调试
来源:
http://www.cnblogs.com/itech/archive/2012/09/23/2698838.html
参考:
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脚本:
$ echo -n 'a=b;c=d' | REQUEST_METHOD=POST CONTENT_LENGTH=999 perl index.cgi
通过get方式来调用cgi脚本:
$ perl index.cgi 'a=b;c=d'
2)
For example, with the following program (notice -debug in the arguments to use 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 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)
当用get方式时,设置环境变量 QUERY_STRING (实例在windows上)
set QUERY_STRING=recipient=John@Doe.com&Fullname=M+Name
perl -w scriptname.cgi
当用post方式时,需要将query_string的内容输入到临时文件testinput.txt,例如
echo recipient=John@Doe.com&Fullname=M+Name >testinput.txt perl -w scriptname.cgi < testinput.txt
三 来自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, letting 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
perl-cgi命令行调试的更多相关文章
- linux命令行调试邮件服务器
linux命令行调试邮件服务器 1. Linux客户端调试邮件过程 [root@mxtest ~]# telnet mail.xx.com 25 Trying 172.16.236.103... Co ...
- 方法:怎么用ionic命令行调试你的ionic app
官网上有很详细的解说 http://blog.ionic.io/live-reload-all-things-ionic-cli/ 下面说说我自己的调试过程(android版): 首先用命令行进入你 ...
- 使用GDB命令行调试器调试C/C++程序
原文:http://xmodulo.com/gdb-command-line-debugger.html作者: Adrien Brochard 没有调试器的情况下编写程序时最糟糕的状况是什么?编译时跪 ...
- Perl的命令行参数和ARGV
程序名:$0 $0表示当前正在运行的Perl脚本名.有3种情况: 如果执行方式为perl x.pl,则$0的值为x.pl而非perl命令本身 如果执行方式为./x.pl,则$0的值为./x.pl 如果 ...
- 记录tiny6410 jlink 命令行调试linux-2.6.38内核
1\首先启动nandflash uboot->linux内核->文件系统,进入文件系统命令行 2\启动JLinkGDBServer -device ARM11 3\启动arm-none-e ...
- Perl中命令行参数以及打开管道文件
打开管道文件 Linux提供了管道机制,可以方便应用程序之间的数据传递.在Perl中,扣开和使用管道可采用如下形式的open函数: open(Filehandle,”丨 CMD”); 其中 ...
- 使用GDB命令行调试器调试C/C++程序【转】
转自:https://linux.cn/article-4302-1.html 编译自:http://xmodulo.com/gdb-command-line-debugger.html作者: Adr ...
- 【转载】PDB命令行调试Python代码
转载自这里. (博主按:PDB调试python代码和用GDB调试c++代码很类似) 你有多少次陷入不得不更改别人代码的境地?如果你是一个开发团队的一员,那么你遇到上述境地的次数比你想要的还要多.然而, ...
- 记录ok6410 jlink 命令行调试uboot
1\启动ok6410 进入uboot命令行 2\启动JLinkGDBServer -device ARM11 3\arm-none-eabi-gdb u-boot 初始化脚本 # Connect to ...
随机推荐
- js--javascript中字符串常用操作总结、JS字符串操作大全
字符串的操作在js中非常频繁,也非常重要.以往看完书之后都能记得非常清楚,但稍微隔一段时间不用,便会忘得差不多,记性不好是硬伤啊...今天就对字符串的一些常用操作做个整理,一者加深印象,二者方便今后温 ...
- 一起看看2016中国第三届CSS开发者大会有哪些大咖演讲
中国第三届CSS开发者大会于2016年12月17日在广州举办.由W3C.w3ctech.前端圈主办.本次大会我们将邀请行业内知名讲师,与大家共聚广州,畅聊CSS. 快捷报名通道:http://www. ...
- 《Javascript网页经典特性300例》
<Javascript网页经典特性300例> 基础篇 第1章:网页特性 刷新.后退.前进.关闭.标题.跳转禁止网页放入框架动态加载js避免浏览器使用缓存加载页面 第2章:DOM操作 根据n ...
- 《JS权威指南学习总结--8.5 作为命名空间的函数》
内容要点: 函数作用域的概念:在函数中声明的变量在整个函数体内都是可见的(包括在嵌套的函数中),在函数的外部是不可见的.不在任何函数内声明的变量是全局变量,在整个JS程序中都是可见的. 在JS中 ...
- 《JS权威指南学习总结--6.9序列化对象》
内容要点: 一.JSON.stringify()和JSON.parse() 1.对象序列化(serialization)是指将对象的状态转换为字符串,也可将字符串还原为对象.ES5提供了内置函数JSO ...
- mysql去重的最方便的两种方法
参考资料:http://blog.csdn.net/guocuifang655/article/details/3993612 方法一: 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然m ...
- java 读取excel(Map结构)xls
package com.sun.test; import java.io.FileInputStream;import java.io.FileNotFoundException;import jav ...
- MVC5笔记【一】
一.global.asax文件的作用:全局性配置文件 理解什么是路由? 有什么作用: 路由主要提供一个路由表 请求的时候被加载,请求url要去路由表当中去对照 规则 解析规则 控制器/动作放方法,转移 ...
- Java 工具 JUnit单元测试
Java 工具 JUnit单元测试 @author ixenos 1.1. JUnit单元测试框架的基本使用 一.搭建环境: 导入junit.jar包(junit4) 二.写测试类: 0,一般一个 ...
- hdu_5585_Less Time, More profit(二分+最大权闭合图)
题目链接:hdu_5585_Less Time, More profit 题意: 有n个工厂,每建一个工厂要花费vi,需要时间ti,然后有m个商店,每个商店需要在指定的k个工厂中进货,才能盈利,如果其 ...