判断脚本是否具有交互性

| 暂无评论 | 暂无引用通告

-->

    Perl脚本明显的可以分为两大类:一类是通过终端与实际用户进行交互的程序;另一类是仅仅与其他程序进行通信而不使用终端的程序。下面我们写一个脚本来测试脚本的交互性。脚本内容如下:

#!/usr/bin/perl -w

if(-t STDIN){
        print "终端输入\n";
}else{
        print "非终端输入 ";
}
if(-t STDOUT){
        print "终端输出\n";
}else{
        print "非终端输出 ";
}
 

以下是脚本的运行结果:

[root@supersun terminal]# perl terminaltest.pl
终端输入
终端输出
[root@supersun terminal]# ls |perl terminaltest.pl
非终端输入
终端输出
[root@supersun terminal]# perl terminaltest.pl  >c
[root@supersun terminal]# cat c
终端输入
非终端输出
[root@supersun terminal]# ls |perl terminaltest.pl >cc
[root@supersun terminal]# cat cc
非终端输入
非终端输出

看到这里之后也许你能明白什么叫“与终端交互”了吧!

暂无引用通告

发送引用通告网址: http://supersun.info/mt/mt-tb.cgi/710
如果您想引用这篇日记到您的Blog,请复制上面的链接,放置到您发表文章时的相应界面中。

发表评论

最新资源

  • IMG_1437.JPG
  • line.png
  • bar.png
  • perl_calander.jpg

关于此日记

此日记由 supersun 发表于 2007年8月13日 16:24

此Blog上的上一篇日记写好脚本用于上传公钥

此Blog上的下一篇日记计算网络掩码的脚本

首页归档页可以看到最新的日记和所有日记。