2

I'm trying to call a "App.exe" file (written in cpp) from matlab, that takes as an input a name of a video (string)

I want to use the Function "System" that Execute operating system command and return result to Matlab.

I wrote the following in Matlab:

 system ('App.exe <'  VideoName);

and the following in Cpp:

 // to get the name of the video (the input) from the command.
 std::string str;
 getline(cin, str);
 const char * name = str.c_str();

But its not working. So my question is: How do we call a "App.exe" from matlab (or even cmd) with input. what should I do to get this work?

mtvec
  • 17,846
  • 5
  • 52
  • 83
Howaida Khoureieh
  • 519
  • 2
  • 11
  • 24

1 Answers1

1

I"m not familiar with matlab syntax, but you should probably try putting the whole path to App.exe. It's probable that the working directory of Matlab is not the same directory as where App.exe is. Alternitavely, you could add the directory that App.exe is in into your PATH environment variable (and restart matlab after doing that to ensure that it gets the new value).

Burton Samograd
  • 3,652
  • 19
  • 21
  • its the same directory, i put the matlab file in the same directory as the "app.exe" workspace. If you're not familiar with matlab, then my Question is: How To Call "app.exe" from Cmd ? What to write (after changing the path) ?! pay attention that it gets a string as an input – Howaida Khoureieh May 01 '12 at 15:53
  • But app.exe takes an input. How To add it? – Howaida Khoureieh May 01 '12 at 16:38
  • Normally you would pass the input as a parameter using argv. Then you can just run cmd /c "/path/to/app.exe input" without having to worry about redirections. In this case input would be in argv[1]. – Burton Samograd May 01 '12 at 16:47
  • To call the following command in Cmd: "app.exe nameOfvid" and then do the following in C++: "std::string str = argv[1]; const char * nameOfvid = str.c_str();" ?!!!!?! – Howaida Khoureieh May 01 '12 at 16:54
  • You can just do const char* nameOfvid = argv[1];. – Burton Samograd May 01 '12 at 17:12
  • error C2440: 'initializing' : cannot convert from '_TCHAR *' to 'char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast – Howaida Khoureieh May 01 '12 at 17:35
  • Ok I solved it (See this link http://stackoverflow.com/questions/6006319/converting-tchar-to-string-in-c) @Burton Samograd Thanks Alot For Your Help – Howaida Khoureieh May 01 '12 at 18:00