Question

So I have some temp data in my program (in RAM). I want to somehow make it seem as it is a file (for example for sending it into another program which takes a file link as argument)?

Is it possible?

How to do such thing?

Was it helpful?

Solution

You can do it in C using the popen() function:

FILE *f = popen("program args", "w");
// write your output to f here using stdio
pclose(f);

This is possible if your external program reads its input from stdin.

OTHER TIPS

Why not simply write the file to disk? If writing to disk is too slow, you can pass the FILE_ATTRIBUTE_TEMPORARY flag to CreateFile to keep the data in cache (and avoid writing it to the physical device).

Sometimes the obvious solutions are the best...

If supported by your operating system (Unixoid systems and Windows do), you could try to use memory-mapped files.

You could use pipe()

The pipe() function shall create a pipe and place two file descriptors,
one each into the arguments fildes[0] and fildes[1], that refer to  the
open  file  descriptions for the read and write ends of the pipe. Their
integer values shall be the two lowest available at  the  time  of  the
pipe() call. The O_NONBLOCK and FD_CLOEXEC flags shall be clear on both
file descriptors. (The fcntl() function can be used to set  both  these
flags.)

Yes, it is possible. You can transfer your data to your other application via an interprocess communication mechanism:

  1. Depending on your OS, you have different options here. You could create a pipe, as other posters have mentioned here, as many OSes have pipes.
  2. You could also use shared memory.
  3. You could simply write it out to a file, and then open up that file in your other application.
  4. Many OSes have other techniques you can use.

EDIT: MSDN lists all the IPC mechanisms available for Windows here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top