3

I have certain application that opens a file with given path (presumably with fopen or derivative), reads the file, possibly writes to it and closes it. I have no control over this application other than specifying the path.

What I am trying to do is 'emulate' a file within the local filesystem to pass it to the application. That is, I want the file to appear as an ordinary file in the filesystem, however the streams are redirected to another application that handles them correctly and outputs appropriate data. Essentially, I want to create a pseudo-device, except that it is not a device at all. Is this doable at all? How would I approach this problem?

1 Answer 1

4

Sounds like what you want is a named pipe, which you can create with mkfifo(1). Create the named pipe with the name of the one you want to 'emulate'. Then start the 'other application' and finally start the one that you have no control over. You do need the 'other application' to behave properly - to communicate with the first application in the way it expects. For example, to have data available for the first and then to wait for data from the first.

3
  • Many thanks! :) Never knew about mkfifo, very useful :)
    – norfavrell
    Commented Jan 27, 2013 at 21:45
  • 1
    But be careful, a pipe isn't seekable. Do you need to process the data inmediately, can't you wait until it finishes? Sure there is no -o - (or similar flag) that redirects output to the standard output? This is very common in Unix.
    – vonbrand
    Commented Jan 27, 2013 at 22:19
  • Pipes are also one-directional. If wou want "full-duplex" solution, use unix domain socket. Commented Feb 27, 2016 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .