1

I need to run a C++ executable from a for loop in MATLAB. I have written the following piece of code for the purpose,

EqNumbers = [17 18 20 21 22 23];

for i = 1:length(EqNumbers)

    EqNumber = EqNumbers(i);
    WriteRunE_File(EqNumber);

    filename=['RunE_1.tcl'];
    system(['OpenSees.exe<',filename]);

end

It is working fine most of the time, however, sometimes debug errors (like the one shown below) will appear. It is prompting me for action, if I press the "Abort" button then the program will continue for the next iteration. I just want to make this process automated, every time manually pressing the abort button is not possible for me, because there are more than 1000 iteartions in the program.

enter image description here

I tried using try-catch end as follows, but it did not serve the purpose.

EqNumbers = [17 18 20 21 22 23];


for i = 1:length(EqNumbers)
    try
        % Code to be executed goes here.

        EqNumber = EqNumbers(i);
        WriteRunE_File(EqNumber);

        filename=['RunE_1.tcl'];
        system(['OpenSees.exe<',filename]);
    catch
        disp('An error occurred in Equke');
        disp('Execution will continue.');
    end

end

I am searching for a way to bypass the error message or automatically press the "Abort" button. So that the program will move to the next iteration automatically.

Note:

I don't have access to the C++ source code (all I have is an executable), hence I cannot update the value of citaR. That's why I am looking for a workaround in MATLAB.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
The_Learner
  • 589
  • 1
  • 6
  • 16
  • Somewhere in your C++ code there is an uninitialized variable called `citar`. Initialize it, compile the program and then try again. – Ron Aug 19 '19 at 12:13
  • I know that, but I don't have the source code to update the variable. That's why I am looking for a work around – The_Learner Aug 19 '19 at 12:14
  • In that case you are relying on Undefined Behavior. Don't. – Ron Aug 19 '19 at 12:15
  • So you're asking how to send a keystroke or a mouse-click, to another process, from MATLAB? The [source code](https://github.com/OpenSees/OpenSees) seems to be hosted on GitHub. – Dev-iL Aug 19 '19 at 13:01
  • @Dev-iL, exactly, I am searching for a mouse click to press "Abort" button – The_Learner Aug 19 '19 at 13:07
  • But that doesn't "bypass the error message". It ignores a crash. What makes you think the results of this crashed process are useful? – Lightness Races in Orbit Aug 19 '19 at 13:07
  • In fact, we know that you _do_ have access to the source, because [you were building it in a previous question](https://stackoverflow.com/q/55822782/560648). – Lightness Races in Orbit Aug 19 '19 at 13:10
  • @LightnessRacesinOrbit, That's fine for me, all I want is to move to the next iteration. Whether it bypasses the error message (or) close the message box, does not matter. – The_Learner Aug 19 '19 at 13:12
  • @LightnessRacesinOrbit, Thank you very much, I have access to the overall source code. But I do not have access to the file, in which I have this error. – The_Learner Aug 19 '19 at 13:14
  • 1
    It really does not make sense to accept the subprocess crashing and not finishing its work from some unknown/unpredictable point. You may as well not run it in the first place; that would be better. – Lightness Races in Orbit Aug 19 '19 at 13:16

1 Answers1

5

MATLAB is not popping up this dialog. Your system is.

Someone created a program that uses an uninitialised variable and has undefined behaviour. They built it in debug mode. This combination results in an assertion. You cannot just turn that off.

Even if you could, you are aborting the program. That doesn't mean "ignore the problem": it means "abort the program". It's not completing its work. It's crashed. Every single time.

The executable is faulty. Period.

The author of the program should give you a release version: ideally, a non-buggy one.

Or, since the program is open source and can be found right here, you could try building a fresh version, or debugging it and contributing a fix.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • Can't we bypass that dialogue box in MATLAB?? – The_Learner Aug 19 '19 at 12:52
  • 1
    Again, no. It has nothing to do with MATLAB. The executable is faulty, period. By clicking "abort" you are, well, aborting it. That doesn't mean it works or that it completes its work. Even if you _could_ automate that (which you can't), it would be the wrong solution. – Lightness Races in Orbit Aug 19 '19 at 12:58