从另一个推出一种C ++应用程序,并与它进行通信 [英] Launch one C++ application from another, and communicate with it

查看:194
本文介绍了从另一个推出一种C ++应用程序,并与它进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++(技术上MATLAB MEX)计划,我打算用它来推出一个独立的纯C ++程序从我的系统上。主调用程序可能看起来类似如下:

 无效mexFunction(INT nlhs,mxArray * plhs [],诠释nrhs,常量mxArray * prhs []){
    系统(路径/到/从/程序);
}

从站后推出的,然后,我会希望有第二个MEX程序将与沟通,将数据发送到从属程序。发送的数据将是大十岁上下的C ++数组的形式。

我想,我需要某种形式的句柄到从程序(也许是它的PID),用于从节目听出传入的消息发送消息和presuamably的方式方法。

我在获得独立的C ++程序相互沟通的经验,因此在这方面的任何暗示将AP preciated。此外,如果有任何具体的特定MEX MATLAB告诫,我很想听到这些。


修改:我应该提到,我在Ubuntu建设这一点,但最终会像它在所有平台上工作。平台具体的建议非常值得欢迎的,但多平台的想法真的是我后。


解决方案

您正在寻找一个的 IPC(进程间通信)机制。

加速对这一整章,是一个跨平台解决方案。


  

Boost.Interprocess中已在以下编译器/平台上进行了测试:


 视觉7.1的Windows XP
可视8.0的Windows XP
GCC 4.1.1 MinGW的
GCC 3.4.4的Cygwin
英特尔9.1的Windows XP
GCC 4.1.2的Linux
GCC 3.4.3的Solaris 11
GCC 4.0 Mac系统10.4.1

I have a C++ (technically MATLAB mex) program, which I am planning to use to launch a stand-alone pure C++ slave program on my system. The master calling program may look something like the following:

void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]){
    system ("path/to/slave/program");
}

Once the slave is launched, I would then like to have a second mex program which will communicate with and send data to the slave program. The data sent will be in the form of large-ish C++ arrays.

I imagine that I will need some kind of handle to the slave program (perhaps its pid?), a method for sending messages and presuamably a way for the slave program to listen out for incoming messages.

I have no experience in getting separate C++ programs to communicate with each other, so any hints in this area would be appreciated. In addition, if there are any specific MATLAB mex-specific caveats, I would be interested to hear about these.


EDIT: I should have mentioned that I am building this on Ubuntu, but will ultimately like it to work on all platforms. Platform specific advice very welcome, but multi-platform ideas are really what I'm after.

解决方案

You are looking for an IPC (Interprocess Communication) mechanism.

Boost has an entire chapter on this and is a cross-platform solution.

Boost.Interprocess has been tested in the following compilers/platforms:

Visual 7.1 Windows XP
Visual 8.0 Windows XP
GCC 4.1.1 MinGW
GCC 3.4.4 Cygwin
Intel 9.1 Windows XP
GCC 4.1.2 Linux
GCC 3.4.3 Solaris 11
GCC 4.0 MacOs 10.4.1

这篇关于从另一个推出一种C ++应用程序,并与它进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆