在 Linux/Unix 文件系统上将可执行文件挂载为文件

发布于 2024-07-14 11:02:32 字数 126 浏览 4 评论 0原文

是否可以使可执行文件看起来像 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧时浪漫 2024-07-21 11:02:32

看看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.

以酷 2024-07-21 11:02:32

使用FUSE

Use FUSE

怎言笑 2024-07-21 11:02:32

在类 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.

蹲在坟头点根烟 2024-07-21 11:02:32

似乎您可以将程序的输出通过管道传输到您用来“读取”的任何内容中。 问题是,如果您想在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文