in reply to How to know whether user terminates system("$cmd|more") with q or not?
But it is so weak...system "strace -o /tmp/strace.out -e open,read more @ARGV"; open my $trace, "/tmp/strace.out" or die; my $last = ''; while (<$trace>) { if (/read\(2,\s*"(.*)",\s*1\)\s*=\s*1$/) { $last = $1; } } print "exited with key >$last<\n";
update: How about Ctrl-C?
system "strace -o /tmp/strace.out -e open,read more @ARGV"; open my $trace, "/tmp/strace.out" or die; my $last = ''; while (<$trace>) { if (/read\(2,\s*"(.*)",\s*1\)\s*=\s*1$/ or /--- SIG(\w+)/) { $last = $1; } } print "exited with key >$last<\n";
|
|---|