Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. posix_spawn, returns 1
Qt 6.11 is out! See what's new in the release blog

posix_spawn, returns 1

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #7

    @jsulm , I've modified the function:

    bool clsMainWnd::blnLaunch(QString strApp, QStringList& slstArgs, qint64& int64PID) {
        Q_ASSERT_X(clsMainWnd::mspobjProcess!=nullptr, "blnLaunch", "mspobjProcess is null!");
        int intLastSep = strApp.lastIndexOf(QDir::separator());
        int64PID = 0;
        if ( intLastSep > 0 ) {
            QString strName = strApp.mid(intLastSep + 1)
                   ,strPath = strApp.mid(0, intLastSep + 1);
            if ( mspobjProcess->startDetached(strName, slstArgs, strPath, &int64PID) == true
              && int64PID > 0 ) {
                return true;
            }
            qDebug() << mspobjProcess->error();
        }
        return false;
    }
    

    The result is:

    QProcess::UnknownError
    

    Not terribly helpful.

    Kind Regards,
    Sy

    jsulmJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      @jsulm , I've modified the function:

      bool clsMainWnd::blnLaunch(QString strApp, QStringList& slstArgs, qint64& int64PID) {
          Q_ASSERT_X(clsMainWnd::mspobjProcess!=nullptr, "blnLaunch", "mspobjProcess is null!");
          int intLastSep = strApp.lastIndexOf(QDir::separator());
          int64PID = 0;
          if ( intLastSep > 0 ) {
              QString strName = strApp.mid(intLastSep + 1)
                     ,strPath = strApp.mid(0, intLastSep + 1);
              if ( mspobjProcess->startDetached(strName, slstArgs, strPath, &int64PID) == true
                && int64PID > 0 ) {
                  return true;
              }
              qDebug() << mspobjProcess->error();
          }
          return false;
      }
      

      The result is:

      QProcess::UnknownError
      

      Not terribly helpful.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @SPlatten said in posix_spawn, returns 1:

      strName

      What does it contain when you call startDetached? Did you try with absolute path to the executable?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      SPlattenS 1 Reply Last reply
      0
      • jsulmJ jsulm

        @SPlatten said in posix_spawn, returns 1:

        strName

        What does it contain when you call startDetached? Did you try with absolute path to the executable?

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by SPlatten
        #9

        @jsulm strName contains:

        mdFileIO
        

        I just tried calling the function with the absolute path:

        bool clsMainWnd::blnLaunch(QString strApp, QStringList& slstArgs, qint64& int64PID) {
            Q_ASSERT_X(clsMainWnd::mspobjProcess!=nullptr, "blnLaunch", "mspobjProcess is null!");
            int intLastSep = strApp.lastIndexOf(QDir::separator());
            int64PID = 0;
            if ( intLastSep > 0 ) {
                QString strName = strApp.mid(intLastSep + 1)
                       ,strPath = strApp.mid(0, intLastSep + 1);
                if ( mspobjProcess->startDetached(strApp, slstArgs, strPath, &int64PID) == true
                  && int64PID > 0 ) {
                    return true;
                }
                qDebug() << mspobjProcess->error();
            }
            return false;
        }
        

        Where strApp contains:

        ~/XMLMPAM/config/modules/mdFileIO
        

        Same result.

        Kind Regards,
        Sy

        jsulmJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @jsulm strName contains:

          mdFileIO
          

          I just tried calling the function with the absolute path:

          bool clsMainWnd::blnLaunch(QString strApp, QStringList& slstArgs, qint64& int64PID) {
              Q_ASSERT_X(clsMainWnd::mspobjProcess!=nullptr, "blnLaunch", "mspobjProcess is null!");
              int intLastSep = strApp.lastIndexOf(QDir::separator());
              int64PID = 0;
              if ( intLastSep > 0 ) {
                  QString strName = strApp.mid(intLastSep + 1)
                         ,strPath = strApp.mid(0, intLastSep + 1);
                  if ( mspobjProcess->startDetached(strApp, slstArgs, strPath, &int64PID) == true
                    && int64PID > 0 ) {
                      return true;
                  }
                  qDebug() << mspobjProcess->error();
              }
              return false;
          }
          

          Where strApp contains:

          ~/XMLMPAM/config/modules/mdFileIO
          

          Same result.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #10

          @SPlatten said in posix_spawn, returns 1:

          ~/XMLMPAM/config/modules/mdFileIO

          Try with whole path, without ~ as ~ is resolved by the shell as far as I know.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          SPlattenS 1 Reply Last reply
          2
          • jsulmJ jsulm

            @SPlatten said in posix_spawn, returns 1:

            ~/XMLMPAM/config/modules/mdFileIO

            Try with whole path, without ~ as ~ is resolved by the shell as far as I know.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by SPlatten
            #11

            @jsulm , still having problems:

            bool clsMainWnd::blnLaunch(QString strApp, QStringList& slstArgs, qint64& int64PID) {
                Q_ASSERT_X(clsMainWnd::mspobjProcess!=nullptr, "blnLaunch", "mspobjProcess is null!");
                QString strUserProfile("~");
            
                if ( strApp.contains(strUserProfile) == true ) {
                //Application path contains user proflie reference, replace with actual folder
                    QString strUserFolder(clsDebugService::strGetUserFolder(strUserProfile));
            
                    if ( strUserFolder.endsWith(QDir::separator()) == true ) {
                        strUserFolder = strUserFolder.left(strUserFolder.length() - 1);
                    }
                    strApp = strApp.replace(strUserProfile, strUserFolder);
                }
                int intLastSep = strApp.lastIndexOf(QDir::separator());
                int64PID = 0;
                if ( intLastSep > 0 ) {
                    QString strName = strApp.mid(intLastSep + 1)
                           ,strPath = strApp.mid(0, intLastSep + 1);
                    if ( mspobjProcess->startDetached(strApp, slstArgs, strPath, &int64PID) == true
                      && int64PID > 0 ) {
                        return true;
                    }
                    qDebug() << mspobjProcess->error();
                }
                return false;
            }
            

            After replacing "~" strApp now contains:

            "/Users/simonplatten/XMLMPAM/config/modules/mdFileIO"
            

            Although I get exactly the same results.

            QProcess::UnknownError
            

            [Edit] I just copied the path and app name and pasted into a terminal, I get:

            Last login: Mon Sep 28 09:04:18 on ttys001
            You have new mail.
            simonplatten@Simons-iMac ~ % /Users/simonplatten/XMLMPAM/config/modules/mdFileIO 
            zsh: operation not permitted: /Users/simonplatten/XMLMPAM/config/modules/mdFileIO
            

            Kind Regards,
            Sy

            JonBJ 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @jsulm , still having problems:

              bool clsMainWnd::blnLaunch(QString strApp, QStringList& slstArgs, qint64& int64PID) {
                  Q_ASSERT_X(clsMainWnd::mspobjProcess!=nullptr, "blnLaunch", "mspobjProcess is null!");
                  QString strUserProfile("~");
              
                  if ( strApp.contains(strUserProfile) == true ) {
                  //Application path contains user proflie reference, replace with actual folder
                      QString strUserFolder(clsDebugService::strGetUserFolder(strUserProfile));
              
                      if ( strUserFolder.endsWith(QDir::separator()) == true ) {
                          strUserFolder = strUserFolder.left(strUserFolder.length() - 1);
                      }
                      strApp = strApp.replace(strUserProfile, strUserFolder);
                  }
                  int intLastSep = strApp.lastIndexOf(QDir::separator());
                  int64PID = 0;
                  if ( intLastSep > 0 ) {
                      QString strName = strApp.mid(intLastSep + 1)
                             ,strPath = strApp.mid(0, intLastSep + 1);
                      if ( mspobjProcess->startDetached(strApp, slstArgs, strPath, &int64PID) == true
                        && int64PID > 0 ) {
                          return true;
                      }
                      qDebug() << mspobjProcess->error();
                  }
                  return false;
              }
              

              After replacing "~" strApp now contains:

              "/Users/simonplatten/XMLMPAM/config/modules/mdFileIO"
              

              Although I get exactly the same results.

              QProcess::UnknownError
              

              [Edit] I just copied the path and app name and pasted into a terminal, I get:

              Last login: Mon Sep 28 09:04:18 on ttys001
              You have new mail.
              simonplatten@Simons-iMac ~ % /Users/simonplatten/XMLMPAM/config/modules/mdFileIO 
              zsh: operation not permitted: /Users/simonplatten/XMLMPAM/config/modules/mdFileIO
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #12

              @SPlatten
              What is your question? If you cannot execute /Users/simonplatten/XMLMPAM/config/modules/mdFileIO, e.g. from zsh, then you cannot execute it, and Qt QProcess won't solve that.

              From what very little I know (I'm not Mac), have you tried Googling for zsh: operation not permitted? You get hits telling you why this happens under various MacOS incarnations and what you are supposed to do about it to allow it to run. [Looks like it's some Mac addition for "security" purposes.]

              SPlattenS 1 Reply Last reply
              0
              • JonBJ JonB

                @SPlatten
                What is your question? If you cannot execute /Users/simonplatten/XMLMPAM/config/modules/mdFileIO, e.g. from zsh, then you cannot execute it, and Qt QProcess won't solve that.

                From what very little I know (I'm not Mac), have you tried Googling for zsh: operation not permitted? You get hits telling you why this happens under various MacOS incarnations and what you are supposed to do about it to allow it to run. [Looks like it's some Mac addition for "security" purposes.]

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #13

                @JonB , I will look into it, thank you...its very odd, I am an Amin on the system.

                Kind Regards,
                Sy

                SPlattenS 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @JonB , I will look into it, thank you...its very odd, I am an Amin on the system.

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #14

                  @JonB ,@jsulm , got it I think, the application created by Qt Creator is not actually a file, but instead a folder:

                  drwxr-xr-x  3 simonplatten  staff     96 28 Sep 07:29 mdFileIO.app
                  

                  If I then go into this folder the actual executable is located in:

                  /Users/simonplatten/build-mdFileIO-Desktop_Qt_5_14_2_clang_64bit-Release/mdFileIO.app/Contents/MacOS/mdFileIO
                  

                  ls -l:

                  -rwxr-xr-x  1 simonplatten  staff  81280 28 Sep 07:29 mdFileIO
                  

                  I can run this application.

                  Kind Regards,
                  Sy

                  SPlattenS 1 Reply Last reply
                  1
                  • SPlattenS SPlatten

                    @JonB ,@jsulm , got it I think, the application created by Qt Creator is not actually a file, but instead a folder:

                    drwxr-xr-x  3 simonplatten  staff     96 28 Sep 07:29 mdFileIO.app
                    

                    If I then go into this folder the actual executable is located in:

                    /Users/simonplatten/build-mdFileIO-Desktop_Qt_5_14_2_clang_64bit-Release/mdFileIO.app/Contents/MacOS/mdFileIO
                    

                    ls -l:

                    -rwxr-xr-x  1 simonplatten  staff  81280 28 Sep 07:29 mdFileIO
                    

                    I can run this application.

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #15

                    @JonB , @jsulm So I simplified my application, commenting out the entire content of main and replacing with just:

                    printf("Hello World\n");
                    return 0;
                    

                    This worked without fault, so now I've put back the original and will investigate what exactly is causing the problems.

                    Kind Regards,
                    Sy

                    1 Reply Last reply
                    1
                    • SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #16

                      It makes 0 sense to me, I've put it back exactly the way it was, in fact all I did was undo until it was as it was...rebuilt and now it works!

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved