在 Linux/Unix 文件系统上将可执行文件挂载为文件
是否可以使可执行文件看起来像 Linux 上的只读文件,这样打开“文件”进行读取实际上会执行该文件,并使其 stdout 可用于读取,就好像它是“文件”中的数据一样? 它应该可以由任何知道如何打开文件进行读取的程序打开,例如“cat”。
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'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看
popen
。 基本上你所描述的是一个管道。PS如果您需要特定于语言的帮助,请编辑问题并添加您正在使用的语言/环境,我将尝试提供更多细节。
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.
使用FUSE
Use FUSE
在类 UNIX 操作系统上,您可以将程序的输出发送到另一个程序打开的命名管道。 查看 mkfifo 命令来创建命名管道。 命名管道的工作方式很像文件,但有一些限制。 例如,它是不可查找的。
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.
似乎您可以将程序的输出通过管道传输到您用来“读取”的任何内容中。 问题是,如果您想在 emacs 或 vim 等中打开可执行文件,那么这与可执行文件无关,因为编辑器不知道任何其他方式来解释它。
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.