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?

| improve this question | | | | |

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.

| improve this answer | | | | |
  • Many thanks! :) Never knew about mkfifo, very useful :) – norfavrell Jan 27 '13 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 Jan 27 '13 at 22:19
  • Pipes are also one-directional. If wou want "full-duplex" solution, use unix domain socket. – el.pescado Feb 27 '16 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.