Is there a way to take a process substitution like <(grep foo some/file)
, and save it to a "file-like entity" on disk (reminiscent of a fifo), so that, every time this thing was opened for reading by some process P
, the grep foo some/file
command (or whatever) would get run anew, and the output returned as the content being read by the process P
?
Asked
Active
Viewed 242 times
1

Michael Homer
- 76,565

kjo
- 15,339
- 25
- 73
- 114
1 Answers
3
This isn't possible with standard UNIX/POSIX facilities. Your imperfect options are:
- Just use a shell script, and have the "opening" application (or your shell) execute it instead of opening it for reading. Some apps may support doing this, otherwise you'll have to resort to a shell script wrapper.
- Use a fifo, and write a daemon that writes to it. This of course means you need to have the daemon started, and it won't work correctly if the fifo is opened multiple times simultaneously.
- Use a virtual filesystem, e.g. FUSE on Linux, to present a virtual file with the semantics that you want. You still need a daemon that implements the virtual filesystem for this.

marcan
- 958
-
+1. Another option is to write a simple network service that outputs the required data (and run it as a standalone daemon or from
inetd
orxinetd
or similar). client would make a tcp connection to the address (e.g. localhost) and port to get the data. If you write it as a standalone, you have a lot more flexibility but you'll have to write your own code to handle multiple simultaneous connections (or use the appropriate library for your language of choice). – cas May 14 '16 at 04:08
<(blah blah)
and that's what it does... Trycat <(date)
then after a few seconds run it again. – don_crissti May 14 '16 at 00:16ls
, etc. It has no content though; or rather, its content gets generated dynamically whenever a process attempts to read it. – kjo May 14 '16 at 00:23mkfifo
and have a writer queued on it within a loop. Downsides are: 1, that the writer would have already started, sodate
for example would be the time the command started rather than the time its output was consumed. 2, you'd have processes active (although blocked) using static resources. Thinking some more, you might be able to do something withsocat
. – Chris Davies May 14 '16 at 00:44/proc
or/sys
but set up with customized contents. – Wildcard May 14 '16 at 00:49