因此,我的程序(在RAM)中有一些临时数据。我想以某种方式使它看起来像一个文件(例如,将其发送到将文件链接作为参数的另一个程序中发送)?

可能吗?

如何做这样的事情?

有帮助吗?

解决方案

您可以在C中使用 popen() 功能:

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

如果您的外部程序从中读取其输入,这是可能的 stdin.

其他提示

为什么不简单地将文件写入磁盘?如果写入磁盘太慢,您可以通过 FILE_ATTRIBUTE_TEMPORARY 标记为 CreateFile 将数据保存在缓存中(并避免将其写入物理设备)。

有时明显的解决方案是最好的...

如果您的操作系统(Unixoid Systems和Windows Do)支持,您可以尝试使用 内存映射文件.

您可以使用管道()

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.)

对的,这是可能的。您可以通过 分解通信 机制:

  1. 根据您的操作系统,您在这里有不同的选择。您可以像其他海报一样创建管道,因为许多OS都有管道。
  2. 您也可以使用共享内存。
  3. 您可以简单地将其写入文件,然后在其他应用程序中打开该文件。
  4. 许多OS都有您可以使用的其他技术。

编辑:MSDN列出了Windows的所有IPC机制 这里.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top