0

In MATLAB itself, it is very easy to call system commands, such as the following:

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

(Note: using Ubuntu)

From C(++) programs, I can execute system commands using std::system:

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

But how can I execute system commands from MATLAB Mex programs?

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

^^The above compiles, but doesn't output anything to screen when run.

Bill Cheatham
  • 11,396
  • 17
  • 69
  • 104

1 Answers1

1

I think you should have a look at that thread:

Capturing stdout from a system() command optimally

#include <stdio.h>

FILE *popen(const char *command, const char *type);

int pclose(FILE *stream);
Community
  • 1
  • 1
Oli
  • 15,935
  • 7
  • 50
  • 66