Rpipe | Pipe semantics in R -
kandi X-RAY | Rpipe Summary
kandi X-RAY | Rpipe Summary
Pipe semantics in R
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Rpipe
Rpipe Key Features
Rpipe Examples and Code Snippets
Community Discussions
Trending Discussions on Rpipe
QUESTION
I just read some Go code that does something along the following lines:
...ANSWER
Answered 2021-Apr-03 at 19:03That code is typical of a program that wants to read output generated by some other program. The os.Pipe()
function returns a connected pair of os.File
entities (or, on error—which should not be simply ignored—doesn't) where a write on the second (w
or wpipe
) entity shows up as readable bytes on the first (r
/ rpipe
) entity. But—this is the key to half the answer to your first question—how will a reader know when all writers are finished writing?
For a reader to get an EOF indication, all writers that have or had access to the write side of the pipe must call the close
operation. By passing the write side of the pipe to a program that we start with cmd.Start()
, we allow that command to access the write side of the pipe. When that command closes that pipe, one of the entities with access has closed the pipe. But another entity with access hasn't closed it yet: we have write access.
To see an EOF, then, we must close off access to our wpipe
, with wpipe.Close()
. So that answer the first half of:
- Why is
inst.wpipe
closed and set to nil?
The set-to-nil
part may or may not have any function; you should inspect the rest of the code to find out if it does.
- Is
dup2(pipe_fd[1], 1)
the C analogue ofcmd.Stdout = inst.wpipe; inst.wpipe.Close()?
Not precisely. The dup2
level is down in the POSIX OS area, while cmd.Stdout
is at a higher (OS-independent) level. The POSIX implementation of cmd.Start()
will wind up calling dup2
(or something equivalent) like this after calling fork
(or something equivalent). The POSIX equivalent of inst.wipe.Close()
is close(wfd)
where wfd
is the POSIX file number in wpipe
.
In C code that doesn't have any higher level wrapping around it, we'd have something like:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Rpipe
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page