1

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

user3443063
  • 1,455
  • 4
  • 23
  • 37
  • "Either in `c_str` or in `system`" - I believe that you can check it yourself? Anyway, system(3) - Linux man page: "The value returned is -1 on error (e.g., fork(2) failed), and the return status of the command otherwise. This latter return status is in the format specified in wait(2)." So just verify the return status of your Fortran script and debug your code. – pptaszni Jul 26 '18 at 09:32
  • 3
    Why do you call `system` *twice* with the same argument? – Some programmer dude Jul 26 '18 at 09:48
  • 1
    Depending on the command interpreter or shell, redirection to a file using `>` can fail if the file already exists. – Peter Jul 26 '18 at 10:47
  • I ssupect you're not really familiar with C++? `.c_str()` is a member function, `system()` is a non-member function. C++ doesn't have "commands". – MSalters Jul 26 '18 at 13:28

1 Answers1

0

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350