I have two programs P
(producer) and C
(consumer). P can be run in such a way that writes to stdout
. But C
is a legacy program that only reads from a file on disk. As in ./C -f </path/to/file>
.
On Linux (or macOS), is there a way to directly pipe P
to C
without writing to a temporary named file on disk that needs to be later cleaned up?
Background: in my use case P
is a password manager from which I would like to retrieve an ephemeral secret. C
is my app that needs to use the secret from a “keyfile”. In this particular scenario, P
is the 1Password cli client and C
is kinit
, and the keyfile is a keytab that I don’t want to store anywhere on disk.
2
Sounds like a great usecase for a named pipe. You create a named pipe on linux using the mkfifo
command which, when ran, creates something that looks just like a file.
mkfifo /path/to/file
Now you can do your ./C -f /path/to/file
and the program will sit and try to read from the file.
In a separate shell you can do your ./P > /path/to/file
and the stdout
will be redirected to the named pipe where the ./C
program will read it in.
Check out this question and its answers for some simple examples of named pipe usage in linux