英文:
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".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论