Is it possible to make an executable look like a read-only file on Linux, such that opening the "file" for reading actually executes the file and makes its stdout available for reading as if it were data in the "file"? It should be openable by any program that knows how to open a file for reading, for example 'cat'.
+6
A:
Look at popen
. Basically what you are describing is a pipe.
P.S. If you need language specific help, edit the question and add the language/environment you're working in and I'll try to provide more specifics.
MarkusQ
2009-02-27 17:35:44
Maybe even more like the /proc "filesystem"...
dmckee
2009-02-27 17:37:27
Huh? He's wanting the output of the executable. How would '/proc "filesystem"' help?
MarkusQ
2009-02-27 17:47:49
He says 'such that opening the "file" for reading actually executes the file and 'makes its stdout available for reading', which isn't quite a pipe and isn't quite like /proc (because that runs in kernel space), but...
dmckee
2009-02-28 01:43:54
You're right, dmckee, I'm not looking for a pipe. I want something that can be opened by any arbitrary program that knows how to open a file for reading. I should have been more clear in my question.
kbluck
2009-03-04 17:18:37
kbluck -- a named pipe can be opened from any arbitrary program that can knows how to open a file for reading.
MarkusQ
2009-03-04 18:18:41
True enough, but I was responding to your original suggestion of popen. A named pipe still doesn't meet the other part of my requirement in that opening the read side of the pipe does not automatically execute the process and connect it to the write side of the pipe.
kbluck
2009-05-20 23:45:08
+2
A:
On unix-like OS's you can send the output of a program to a named pipe that is opened by another program. Look at the mkfifo command to create the named pipe. The named pipe works a lot like a file, with some limitations. For example, it is not seekable.
karunski
2009-02-27 17:39:00
A:
Seems like you could pipe the output of the program into whatever you are using to "read". The problem is if you want to open the executable in say emacs or vim or whatever, it's not a matter of the executable so much as the editor doesn't know any other way to interpret it.
ras2124
2009-02-27 17:39:43