Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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