开发者

How can I trap Cntl-C while using Perl's Term::ShellUI?

开发者 https://www.devze.com 2022-12-23 08:12 出处:网络
I used Term::ShellUI and almost every thing is working as expected but the issue is when I pressed Ctrl-C I want to

I used Term::ShellUI and almost every thing is working as expected but the issue is when I pressed Ctrl-C I want to print:

Please use 开发者_开发知识库ctrl+d to exit the shell

For that I handle the signal but the message print only after I pressed the new line How to resolve this?


You can do the same without using the IO::Handle library, by setting the $| variable to 1 before printing.

$SIG{INT} = sub {
   $| = 1;
   print "Please use ctrl+d to exit the shell";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号