user3396218
user3396218

Reputation: 255

How to hide Matlab Command Window and command prompt from calling system in C++

I execute the Matlab script file using system() which uses the command prompt and it's working fine. But i wish to hide everything and hope it runs in the background and only showing my GUI from the script file. Any idea?

This is my command in MSVS C++ (Note : i cut short the path name for simplicity purposes) :

system("\"\"C:\\matlab.exe\" -nodisplay -nosplash -nodesktop -r \"run('C:\\main.m');\"\"");

Upvotes: 0

Views: 767

Answers (2)

Edric
Edric

Reputation: 25160

You might be better off using the MATLAB Engine API.

Upvotes: 0

ooga
ooga

Reputation: 15511

You could try CreateProcess instead of system. A simple example:

#include <windows.h>
#include <stdio.h>

int main() {
  PROCESS_INFORMATION pi;
  STARTUPINFO si = {
    sizeof(si),
    NULL, NULL, NULL,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    NULL, NULL, NULL, NULL
  };

  BOOL res = CreateProcess(
    NULL,
    "C:\\matlab.exe -nodisplay -nosplash -nodesktop -r \"run('C:\\main.m');\"",
    NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL,
    NULL,   // starting directory (NULL means same dir as parent)
    &si, &pi
  );

  if (res == FALSE) printf("CreateProcess failed\n");

  return 0;
}

Upvotes: 1

Related Questions