Re: [Rd] Reading exit code of pipe()

2015-05-14 Thread William Dunlap
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 kevinus...@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.o...@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@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-devel

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Reading exit code of pipe()

2015-05-14 Thread Gábor Csárdi
On Thu, May 14, 2015 at 1:27 AM, Kevin Ushey kevinus...@gmail.com wrote:
[...]

 So maybe `cat` just doesn't set a status code, and so there's nothing
 for R to forward back (ergo -- NULL)?


cat definitely sets the status. IMHO every command sets the exit status, by
definition, at least on Unix/Linux.

/tmp$ touch x
/tmp$ cat x
/tmp$ echo $?
0
/tmp$ cat y
cat: y: No such file or directory
/tmp$ echo $?
1

Gabor

[...]

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Reading exit code of pipe()

2015-05-14 Thread Jeroen Ooms
On Thu, May 14, 2015 at 7:30 AM, William Dunlap wdun...@tibco.com wrote:
 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) or via something like readLines() or scan() 
 (close() returns status integer).

Hmm interesting. It doesn't help me though; the connection has to be
explicitly opened to support streaming otherwise it keeps running the
command over and over again:

 con - pipe(ls -ltr /)
 readLines(con, n = 3)
 readLines(con, n = 3)
 readLines(con, n = 3)
 isOpen(con)

Under the hood, R distinguishes closing and destroying the
connection. The R function close actually means destroy. It seems like
the pipe exit code is only properly returned if the connection was
already closed but not destroyed by the time close() was called.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Reading exit code of pipe()

2015-05-14 Thread Tim Keitt
Not sure if it helps for your use case, but I have an experimental package
for controlling bidirectional pipe streams from R. Just thought I'd mention
it. Its at

https://github.com/thk686/pipestreamr

THK

On Thu, May 14, 2015 at 9:30 AM, William Dunlap wdun...@tibco.com wrote:

 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 kevinus...@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.o...@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@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-devel
 
  __
  R-devel@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-devel
 

 [[alternative HTML version deleted]]

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel




-- 
Timothy H. Keitt
http://www.keittlab.org/

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Reading exit code of pipe()

2015-05-13 Thread Kevin Ushey
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.o...@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@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel