How can I check the status of the first program in pipeline in Perl's system()?

后端 未结 7 541
小蘑菇
小蘑菇 2021-01-21 06:41
perl -e \'system (\"crontab1 -l\");print $?\'

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

perl -e \'system (\"crontab1 -l|         


        
7条回答
  •  伪装坚强ぢ
    2021-01-21 07:33

    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 $?;
    

    as an example.

提交回复
热议问题