juriguen
juriguen

Reputation: 21

Running exe code from Matlab. The exact same instruction that works in cmd (dos) fails from Matlab

This is driving me crazy, I must admit. After finally being able to successfully compile two functions I need to process voice files, from C/C++ code that I downloaded from a trustworthy online repository (code that had been thoroughly tested in Linux), I am now struggling to launch those files from Matlab...

When I type the following command in cmd (dos) Analysis b2.wav config_default it works, no problem (see here Works).

Then, I build the exact same command into a string and feed it to the "system" Matlab function. Then the code crashes... (see here Fails) I've tried with full paths (c:\b2.wav, etc) but still does not work...

Any ideas as to why this might be happening?

Upvotes: 1

Views: 128

Answers (2)

Leon Carlo Valencia
Leon Carlo Valencia

Reputation: 8767

Based on what's been tried so far and the outputs, here's my theory:

  • Premise: Analysis.exe came from code that's well tested in Linux. It works in Windows command line when run from the same directory where both it and the target file reside. But it stops working from Matlab console.
  • Assertion 1: Matlab console does not operate within the context of the directory where the binary is but rather within the Matlab directory. As such, Analysis.exe will try to find the target from the Matlab directory.
  • Validation for Assertion 1: Try putting the binary and the target wav in the Matlab directory. Then run system with the binary and target specified just by name (no path).
  • Assertion 2: If the file's full path is specified to address this issue, it still doesn't work. This may be because the code assumed a Linux file system where the delimiter is "/" rather than "\".
  • Validation for Assertion 2: Run with paths specified from the command line while in a diferent directory to see if it fails or not.
  • Possible Solution 1: Add the directory where both Analysis.exe and the target are into the Matlab path: (1) On the Home tab, in the Environment section, click Set Path. Add the path there. (2) addpath (folderName1,...,folderNameN) adds the specified folders to the top of the search path for the current MATLAB session. -> Then run the system command without the full paths.
  • Possible Solution 2: Add the directory where both Analysis.exe and the target are into the Windows environment path. Then run the system command without the full paths.

EDIT: Possible hackish solution - Create a batch file where: (1) you would cd to the directory where Analysis.exe and the target wav are; and (2) do a Matlab system call to the batch file.

EDIT 2: Possible experiment to validate assertion 2.

Upvotes: 1

user2261062
user2261062

Reputation:

Your image shows that the program Analysis stopped unexpectedly.

It might be a lot of reasons why, so let's go step by step:

1) Try executing Analysis from Terminal and passing wrong parameters (a file that doesn't exist, only one param (missing the config_defalut), no parameters at all, three parameters, etc...)

Can you make the program crash from terminal by passing wrong params?

2) Try creating the command first, checking that it's correct (\b is actually \b instead of a string modifier)

command_to_be_run = 'C:\Analysis C:\b2.wav C:\config_default'
disp(command_to_be_run)     % is it showing exacly what you want?
system(command_to_be_run);  % if so, run it.

3) Try creating a dummy executable dummy.exe in C that accepts two parameters and prints the received parameters (keep it super simple, just printing). Call it from Terminal. Does it work? Call it from Matlba. Does it Work?

With this 3 tests you can considerably narrow down where your error comes from.

By the way, is "config_default" a file or just a string that tells analysis how to behave? In some examples you treat it as a file, in others as a parameter without path.

Upvotes: 2

Related Questions