I have a powershell function that processes a list of files. I use the begin
, process
and end
blocks for this:
begin {
# prepate some stuff
}
process {
# process each file
}
end {
# clean up
}
Now, when I hit Ctrl+C, the whole script just terminates right at the spot where it was. That’s not really a problem for the process part as that will only do permanent changes on the very last command.
I do however still want to execute what’s in the end
block to clean it up a bit, and to print some statistics about the files that did manage to get processed.
Is there a clean way to catch keyboard interrupts, while keeping the begin/process/end structure?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…