From wdunlap at tibco.com  Thu May 14 16:30:58 2015
From: wdunlap at tibco.com (William Dunlap)
Date: Thu, 14 May 2015 07:30:58 -0700
Subject: [Rd] Reading exit code of pipe()
In-Reply-To: <CAJXgQP3TH2xmyhBCoOow9XzxXzQdvAL0RnLCof8=zd1s1kLXQw@mail.gmail.com>
References: <CABFfbXv7OzDSt3n9HwkG3Oat0sH3t47LYQZT7ja7QBJQOY9sGw@mail.gmail.com>
	<CAJXgQP3TH2xmyhBCoOow9XzxXzQdvAL0RnLCof8=zd1s1kLXQw@mail.gmail.com>
Message-ID: <CAF8bMcZkKrhafAmWuywyPiTXiiJNFwCcXdWyXR3kJmz+mnQBPQ@mail.gmail.com>

The difference in the return value of close(pipeConnectionObject)
seems to depend on whether the pipe connection was opened via
the pipe() or open() functions (close() returns NULL)
   > con <- pipe("ls")
   > open(con, "r")
   > readLines(con, n=1)
   [1] "1032.R"
   > print(close(con))
   NULL
   > con <- pipe("ls", "r")
   > scan(con, n=1, what="")
  Read 1 item
  [1] "1032.R"
  > print(close(con))
  NULL
or via something like readLines() or scan() (close() returns status
integer).
  > con <- pipe("ls")
  > scan(con, n=1, what="")
  Read 1 item
  [1] "1032.R"
  > print(close(con))
  [1] 36096
  > sprintf("0x%x", .Last.value)
  [1] "0x8d00"






Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, May 13, 2015 at 10:27 PM, Kevin Ushey <kevinushey at gmail.com> wrote:

> Hi Jeroen,
>
> I think `pipe` might just be returning the status code of the
> underlying command executed; for example, I get a status code of '0'
> when I test a pipe on `ls`:
>
>     conn <- pipe("ls")
>     stream <- readLines(conn)
>     print(close(conn))
>
> Similarly, I get an error code if I try to `ls` a non-existent
> directory (512 in my case), e.g.
>
>     conn <- pipe("ls /no/path/here/sir")
>     stream <- readLines(conn)
>     print(close(conn))
>
> So maybe `cat` just doesn't set a status code, and so there's nothing
> for R to forward back (ergo -- NULL)?
>
> Kevin
>
> On Wed, May 13, 2015 at 5:24 PM, Jeroen Ooms <jeroen.ooms at stat.ucla.edu>
> wrote:
> > Is there a way to get the status code of a pipe() command? The
> > documentation suggests that it might be returned by close, however
> > this does not seem to be the case.
> >
> >   con <- pipe("cat /etc/passwd", "r")
> >   stream <- readLines(con, n = 10)
> >   err <- close(con)
> >   print(err)
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



[Rd] Reading exit code of pipe()
William Dunlap