Thread exit() abfangen
(12 answers)
Opened by bianca at 2016-08-27 09:02
a.pl
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #!/usr/bin/perl use strict; use warnings; use 5.010; use utf8; say "jetzt soll exit() abgefangen werden"; *CORE::GLOBAL::exit = sub { say "exit() sub"; }; # Quelle: http://stackoverflow.com/a/25376064 do "sub.pl"; sub_code('foo'); say "jetzt soll exit() wiederhergestellt werden"; *CORE::GLOBAL::exit = *CORE::exit; # Quelle: http://stackoverflow.com/a/25376064 do "sub.pl"; sub_code('bar'); say "dieser Text darf nicht mehr zu sehen sein"; sub.pl Code (perl): (dl
)
1 2 3 4 5 6 ################################################# sub sub_code { print "bin im sub_code mit Par. '$_[0]'", "\n"; exit(); } ################################################# ergibt: C:\>perl a.pl jetzt soll exit() abgefangen werden bin im sub_code mit Par. 'foo' exit() sub jetzt soll exit() wiederhergestellt werden bin im sub_code mit Par. 'bar' |