Now, if I run this, and I press Ctrl-C, I either get something like this (note, the _ indicates position of terminal cursor after script has terminated):MYPROMPT$ ./test.plcnEEEEEcnt: 0MYPROMPT$ _cntB: 2Exiting或:MYPROMPT$ ./test.plcncnt: 0MYPROMPT$ _cntB: 2Exiting ...但是,我想得到:... however, I'd like to get:MYPROMPT$ ./test.plcncnt: 0cntA: 1cntB: 2ExitingMYPROMPT$ _很显然,处理程序正在运行-但是我期望它们的时间安排(或顺序)不够.有人可以澄清如何解决此问题,以便获得所需的输出吗?Obviously, handlers are running - but not quite in the timing (or order) I expect them to. Can someone clarify how do I fix this, so I get the output I want?在此先感谢您的回答,干杯!Many thanks in advance for any answers,Cheers!推荐答案 Hmmm ...似乎解决方案比我想象的要容易:)基本上,对陷阱出口"的检查应在打印行之后执行-但在打印出向上三行"的字符;也就是说,该部分应为:Hmmm... seems solution was easier than I thought :) Basically, the check for "trapped exit" should run after the lines are printed - but before the characters for "go three lines up" are printed; that is, that section should be: printf "cnt: %10d\n", $cnt; printf "cntA: %10d\n", $cnt+1; printf "cntB: %10d\n", $cnt+2; if ($toexit) { die "Exiting\n" ; } ; print "\033[3A"; # in bash - go three lines up print "\033[1;35m"; # in bash - add some color ...,然后Ctrl-C上的输出似乎是:... and then the output upon Ctrl-C seems to be like:MYPROMPT$ ./test.plcnt: 0^CcntA: 1cntB: 2ExitingMYPROMPT$ _好吧,希望这可以对某人有所帮助,干杯!Well, hope this may help someone,Cheers! 这篇关于Perl在bash中捕获Ctrl-C(sigint)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 05:48