在perl中,检测shell脚本返回值
2012-04-03 23:48
369 查看
使用perl调用外名命令有很多方法,这里就不详细讲解。
如有shell脚本a.sh
#!/bin/bash
echo "script out put"
exit 2
有perl脚本test.pl调用a.sh
#!/bin/perl -w
$output = qx(/usr/local/a.sh);
$exitcode = $?;
print "output = " . $output;
print "exitcode = " . $exitcode;
执行此perl脚本./test.pl
你会发现输出的内容为
output = script out put
exitcode = 512
明显就不是你所期望的结果。输出应该是
output = script out put
exitcode = 2
这才是我们期待的。
原因是,perl内部$?的返回值,会将shell的值乘以8,我们给他除以8,便可以解决。
#!/bin/perl -w
$output = qx(/usr/local/a.sh);
$exitcode = $? >>8;
print "output = " . $output;
print "exitcode = " . $exitcode;
再次运行脚本你会发现OK了。
如有shell脚本a.sh
#!/bin/bash
echo "script out put"
exit 2
有perl脚本test.pl调用a.sh
#!/bin/perl -w
$output = qx(/usr/local/a.sh);
$exitcode = $?;
print "output = " . $output;
print "exitcode = " . $exitcode;
执行此perl脚本./test.pl
你会发现输出的内容为
output = script out put
exitcode = 512
明显就不是你所期望的结果。输出应该是
output = script out put
exitcode = 2
这才是我们期待的。
原因是,perl内部$?的返回值,会将shell的值乘以8,我们给他除以8,便可以解决。
#!/bin/perl -w
$output = qx(/usr/local/a.sh);
$exitcode = $? >>8;
print "output = " . $output;
print "exitcode = " . $exitcode;
再次运行脚本你会发现OK了。
相关文章推荐
- perl 脚本里调用shell 以及获取返回值
- Shell 脚本基础 - 使用 if 语句进行条件检测
- c程序shell脚本获取返回值的方法
- 通过shell批量检测集群跑数据是否异常脚本
- WyBox使用shell脚本检测io口是否正常
- SHELL脚本:检测一坨IP是否都能ping通(网卡监控)
- 用Perl、Shell脚本基于Tomcat6开发cgi程序环境配置
- 用于检测进程的shell脚本代码小结
- shell until循环ping检测ip脚本
- shell脚本检测网络是否畅通
- 自动化下载并检测ftp文件备份的shell脚本
- perl脚本调用shell命令后的结果比较总结
- perl 调用shell脚本
- Shell脚本实现检测Cygwin最快的镜像站点
- 脚本语言语言脚本语言:Shell , JavaScript、VBScript、Perl、PHP、Python、Ruby、Lua
- 使用shell编写一个检测系统参数的脚本
- python调用其它脚本:pig,python,shell等等 (如何获取pig脚本执行的返回值)
- [shell]通过ping检测整个网段IP的网络状态脚本
- shell脚本实现实时检测文件变更
- Shell脚本实现检测文件是否被修改过代码分享