简体   繁体   English

如何在没有NMI的情况下通过内存映射文件在C ++和JAVA之间进行通信?

[英]How to communicate between C++ and JAVA via Memory-Mapped file without NMI?

I have a C++ COMPILED code which takes two arguments: input file & output file. 我有一个C ++ COMPILED代码,它带有两个参数:输入文件和输出文件。 It's also not possible to pipe input and output. 也无法通过管道传递输入和输出。 I want to call this program from a Java application. 我想从Java应用程序调用此程序。 The only performance-improvement option which comes to mind, is to use memory-mapped files. 想到的唯一性能改进选项是使用内存映射文件。 The task is simple: 任务很简单:

  1. create two file (names) 创建两个文件(名称)
  2. call C++ compiled program and provide the file names (code manipulation is not possible, the code is too complicated) 调用C ++编译程序并提供文件名(无法进行代码操作,代码过于复杂)
  3. read output file 读取输出文件

How can I do it in Java? 如何用Java做到这一点?

You can achieve that by: 您可以通过以下方法实现:

try {
  //Start the c++ program
  Process p = Runtime.getRuntime().exec("MyCppProgram.exe "+"intputFile "+"outputFile");
  // wait until the program finishes
  p.waitFor();
  // Done, process output file
}
catch (Exception e) {
  e.printStackTrace();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM