简体   繁体   English

如何检查csh中错误代码的状态?

[英]How to check status of error code in csh?

This is not a Perl questions, this is a csh question.这不是一个 Perl 问题,这是一个 csh 问题。

Perl 5.8.8 on Linux RHEL 5.5.56. Linux RHEL 5.5.56 上的 Perl 5.8.8。

I have a test Perl program which uses 'exit 3;'我有一个使用“exit 3;”的测试 Perl 程序to set the exit status.设置退出状态。 The Perl program is run from a csh script I call 'test'. Perl 程序是从我称为“test”的 csh 脚本运行的。

Perl program: Perl程序:

#/usr/bin/perl
# July 11, 2014
# Test exit code with csh $status variable
my($i);
$i=3;
print "$0 Exit with error code $i\n";
exit $i;

'test' csh script that calls Perl progam:调用 Perl 程序的“测试”csh 脚本:

#/bin/csh
# July 10, 2014,

perl tstatus.pl
echo "Status=$status"
if ($status > 0) then
    echo "ERROR in status: $status"
endif

The line 'echo "ERROR in status: $status" is never executed even though 'echo "Status=$status' says status is 3.即使 'echo "Status=$status' 表示状态为 3,'echo "ERROR in status: $status" 行也不会执行。

How do I get my csh to check and act on the value of $status?如何让我的 csh 检查 $status 的值并采取行动? $status is a system variable it seems. $status 似乎是一个系统变量。

I have also tried 'if ($stats) then' but that doesn't work either.我也试过 'if ($stats) then' 但这也不起作用。 No errors are reported in the csh script. csh 脚本中没有报告错误。

Thank you.谢谢你。

ps I don't do complicated stuff in csh so I'm not ready to go to bash yet. ps 我不会在 csh 中做复杂的事情,所以我还没有准备好去 bash。 I've read the "why not csh" file already.我已经阅读了“为什么不使用 csh”文件。 Thanks.谢谢。

The echo command succeeds, resetting $status to 0. Thus if never sees nonzero $status . echo命令成功,将$status重置$status 0。因此, if从未看到非零$status

Therefore the solution is to either eliminate the echo command or save the value of $status immediately after the perl command.因此,解决方案是消除echo命令或在perl命令之后立即保存$status的值。

I recently encountered a similar issue myself.我最近自己也遇到了类似的问题

every line executed in csh sets $status csh 中执行的每一行都设置 $status

I usually follow any statement, where I want to test the status with something like:我通常遵循任何声明,我想用以下内容测试状态:

set myrc = $status设置 myrc = $status

which will persist regardless of the number of statements that are executed in between call and the evaluation of the result.无论在调用和结果评估之间执行的语句数量如何,它都会持续存在。

eg:例如:

    perl tstatus.pl
    set myrc = $status
    echo "Status=$myrc"
    if ($myrc> 0) then
        echo "ERROR in status: $myrc"
    endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM