【问题标题】:Performing system calls from MATLAB Mex files从 MATLAB Mex 文件执行系统调用
【发布时间】:2012-01-17 22:57:47
【问题描述】:

在 MATLAB 本身中,调用系统命令非常容易,例如:

>> system('ls');
yprime.c    yprime.mexa64

(注意:使用 Ubuntu)

在 C(++) 程序中,我可以使用 std::system 执行系统命令:

#include <cstdlib>
int main()
{
    std::system("ls");
}

但是如何从 MATLAB Mex 程序执行系统命令?

#include <cstdlib>
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
    std::system("ls");
}

^^以上编译,但运行时不向屏幕输出任何内容。

【问题讨论】:

    标签: matlab mex


    【解决方案1】:

    我认为你应该看看那个帖子:

    Capturing stdout from a system() command optimally

    #include <stdio.h>
    
    FILE *popen(const char *command, const char *type);
    
    int pclose(FILE *stream);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多