如何检查Perl的system()中管道中第一个程序的状态? [英] How can I check the status of the first program in pipeline in Perl's system()?

查看:50
本文介绍了如何检查Perl的system()中管道中第一个程序的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

perl -e 'system ("crontab1 -l");print $?'

按预期返回-1(程序crontab1不存在)

returns -1 as expected (program crontab1 doesn't exist)

perl -e 'system ("crontab1 -l|grep blah");print $?'

返回256.

如何检查第一个(或两个)程序的状态?

What is the way to check the status of the first (or both) programs?

推荐答案

您将以应有的方式获取整个命令的退出状态.如果要分别退出状态,则必须分别运行命令.

You are getting the exit status of the entire command, just as you should. If you want the exit status separately, you're going to have to run the commands separately.

#!/usr/bin/perl -e
system("crontab1 -l > /tmp/junk.txt"); print $?;
system("grep blah /tmp/junk.txt"); print $?;

作为示例.

这篇关于如何检查Perl的system()中管道中第一个程序的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆