After recompiling our FORTRAN-code and using it in C++ our system() or c_str() command don`t work properly

66 Views Asked by At

Hi I have a big problem: We created a program in C++/Qt 4.8.4 /Qt Creator 2.8.1 years ago that while executing runs another executable (written and compiled in FORTRAN). Everything worked well.

We recompiled our Fortran-Code with the new version of Visual studio and now suddenly it doesn`t work any more. I looked into my C++-Code and found the position where the program crashes:

  std::string Executable = ApplicationName.toStdString();

  bool RunOK=  system((Executable+" > "+"X.out2").c_str());
  QString  ExeName =  (Executable+" > "+"X.out2").c_str();
  QString tf = QString::number(qweee);

  if(system((Executable+" > "+"X.out2").c_str()))
  {
       msg.showMessage("msg.showMessage("An XXX error occured during calculation......((Executable+ > +X.out2).c_str(): "+ExeName +"......(system((Executable+ > +X.out2).c_str()): "+ QString::number(RunOK));
            if(QFile(OutputFiles[0]).exists())
                QFile(OutputFiles[0]).remove();
   }

Somehow system((Executable+" > "+"X.out2").c_str()) gets to be true which didn`t happen before.

This seems to happen either in the c_str-command or in the system()-command.

We had some missing dll-issues before. Is this another dll-problem and if so which?

Can anybody help us on this?

Thank you

1

There are 1 best solutions below

0
On

The return value of system is an integer, not a boolean. Its value is only defined for one very special case, system(nullptr). That's not the case here. So whether you get a zero or non-zero result depends on your particular C++ implementation, which has indeed changed. ("New visual studio version"). You can't rely on non-zero means error

c_str() is not a suspect at all.