[Rd] Capturing interrupts during the execution of system/system2

From: Gaidatzis, Dimosthenis <Dimosthenis.Gaidatzis_at_fmi.ch>
Date: Thu, 19 Jan 2012 11:56:57 +0000

Dear R Team

I have a question about the system/system2 command in R on linux. My goal is to run a system command (which can take a long time) and to detect if it was successful or not. If i understood correctly the return value of system should give me exactly this information. However if i try to do this, system returns 0, even if i interrupt the execution with CTRL-C (which is the event i would like to detect). Here is an example (just piping /dev/zero to /dev/null) to illustrate the behavior after pressing CTRL-C.

> ret <- system("cat /dev/zero > /dev/null"); print(ret) ^C[1] 0

I also tried to use a tryCatch block to detect this event but pressing CTRL-C during the execution of the system command does not result in a capture of this interrupt event. Only releasing resources is called which happens in any case:

> tryCatch({
+ ret <- system("cat /dev/zero > /dev/null"); print(ret)

+ }, interrupt = function(ex) {

+ cat("An interrupt was detected.\n");
+ print(ex);
+ }, error = function(ex) {

+ cat("An error was detected.\n");
+ print(ex);
+ }, finally = {

+ cat("Releasing resources...");
+ cat("done\n");

+ })
^C[1] 0
Releasing resources...done

Is there still a way to find out if the user stopped the R script while the system command was running?

R version 2.14.1 (2011-12-22)
Platform: x86_64-unknown-linux-gnu (64-bit)

Kind regards
Dimos Gaidatzis

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 19 Jan 2012 - 12:34:20 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 Jan 2012 - 23:50:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive