From kirill.mueller at ivt.baug.ethz.ch  Fri Mar 14 16:03:31 2014
From: kirill.mueller at ivt.baug.ethz.ch (=?windows-1252?Q?Kirill_M=FCller?=)
Date: Fri, 14 Mar 2014 16:03:31 +0100
Subject: [Rd] Detect a terminated pipe
In-Reply-To: <034131C4-F4C4-44C6-BF23-9F8892DD9138@r-project.org>
References: <5322F166.30706@ivt.baug.ethz.ch>
	<034131C4-F4C4-44C6-BF23-9F8892DD9138@r-project.org>
Message-ID: <53231A43.8000603@ivt.baug.ethz.ch>

On 03/14/2014 03:54 PM, Simon Urbanek wrote:
> As far as R is concerned, the connection is open. In addition, pipes exist even without the process - you can close one end of a pipe and it will still exist (that?s what makes pipes useful, actually, because you can choose to close arbitrary combination of the R/W ends). Detecting that the other end of the pipe has closed is generally done by sending/receiving data to/from the end of interest - i.e. reading from a pipe that has closed the write end on the other side will yield 0 bytes read. Writing to a pipe that has closed the read end on the other side will yield SIGPIPE error (note that for text connections you have to call flush() to send the buffer):
>
>> >p=pipe("true","r")
>> >readLines(p)
> character(0)
>> >close(p)
>> >p=pipe("true","w")
>> >writeLines("", p)
>> >flush(p)
> Error in flush.connection(p) : ignoring SIGPIPE signal
>> >close(p)
Thanks for your reply. I tried this in an R console and received the 
error, just like you described. Unfortunately, the error is not thrown 
when trying the same in RStudio. Any ideas?


Cheers

Kirill



[Rd] Detect a terminated pipe
=?windows-1252?Q?Kirill_M=FCller?=