在Linux中创建具有动态内容的文件,除了编写驱动程序之外,是否有可能?

huangapple go评论66阅读模式
英文:

Short of writing a driver, is it possible to create a file in Linux with dynamic contents?

问题

我明白你的要求,以下是你需要翻译的内容:

假设我有以下文件:

a.txt

foo

b.txt

bar

还有一个我无法控制源代码的程序,它从给定的路径读取文件,我是否可以提供一个路径,使它读取的结果就像调用了 cat a.txt b.txt 一样呢?

另外,假设我更改了一个输入文件,如下所示:

b.txt

baz

如果程序再次读取,我希望它现在读取:

foo
baz

我知道我可以使用类似 makefile 的东西来生成这样的文件,但这将涉及每次输入文件更改时都运行 make,而没有其他好处。

英文:

Suppose I had the files

a.txt:

foo

b.txt:

bar

And a program whose source I don't control that reads a given file from a path, is there a path I can give it that would result in it reading

foo
bar

as if it had called cat a.txt b.txt?

Additionally, suppose I changed an input file as such

b.txt:

baz

I would like the program, should it read again, to now read

foo
baz

I'm aware I could use something like a makefile to generate such a file, but that would involve running make every time any of the input files changed for no other benefit.

答案1

得分: 1

我认为你希望,无论a.txt和b.txt中包含什么内容,该应用程序都能够读取c.txt并接收这两个文件的内容。这不能被被动地完成。你需要在某处进行一些处理来进行合并。主动的处理可以写入到一个命名管道,但这不是"永久的"。

英文:

I think you're hoping that, whatever is contained in a.txt and b.txt, the application could read c.txt and receive the contents of both files. That cannot be done passively. You need some process, somewhere, to do the combining. An active process could write to a named pipe, but that's not "permanent".

huangapple
  • 本文由 发表于 2023年7月3日 06:11:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600973.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定