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. problem with System()

problem with System()

Scheduled Pinned Locked Moved Unsolved General and Desktop
system commandsystem
37 Posts 5 Posters 16.8k Views 2 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.
  • SGaistS SGaist

    Hi,

    What does it have to do with Qt ?

    In any case, check the content of your command string.

    Note that you can use QProcess for that kind of task.

    AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by
    #3

    @SGaist Yes, command string is right... but I do not why segmentation fault...
    I am going to check QProcess

    1 Reply Last reply
    0
    • AlvaroSA AlvaroS

      Hello everyone:

      First of all thanks a lot for reading this post and being able to help.
      I have a problem whit System command.

      if I write:

      sprintf(command, "%s %0.0f %0.0f 0 %0.0f %0.0f %s 0 0 +", princi,wps.front().x(), wps.front().y(),wps.back().x(),wps.back().y(),name_bmp);
      
      chdir("/home/"); //To change directory
      system(command);
      

      It give me segmentation fault when it runs system(command)

      However if I write:

      system("./princi 0 747.37 427.68 0 844.37 42.54 prueba_princi.bmp 0 0 +")
      
      

      it runs perfectly....

      What am I doing wrong?
      Thanks!

      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by Joel Bodenmann
      #4

      This is not really an answer to your question but still related: You should consider using the QProcess class. This is not only a lot more flexible & portable than the system() function but also integrates well into the Qt framework (signal&slots, properties, ...).
      Usually you want to use Qt library components wherever possible.

      To still be somewhat useful: Did you check that command is large enough and that the string assembled by sprintf() is correct?

      Edit: @SGaist played ninja again....

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #5

        @AlvaroS said:

        sprintf(command, "%s %0.0f %0.0f 0 %0.0f %0.0f %s 0 0 +", princi,wps.front().x(), wps.front().y(),wps.back().x(),wps.back().y(),name_bmp)

        What types are
        princi
        name_bmp

        better not be QStrings :)

        AlvaroSA 1 Reply Last reply
        3
        • mrjjM mrjj

          @AlvaroS said:

          sprintf(command, "%s %0.0f %0.0f 0 %0.0f %0.0f %s 0 0 +", princi,wps.front().x(), wps.front().y(),wps.back().x(),wps.back().y(),name_bmp)

          What types are
          princi
          name_bmp

          better not be QStrings :)

          AlvaroSA Offline
          AlvaroSA Offline
          AlvaroS
          wrote on last edited by
          #6

          @mrjj Hello.
          They are const char* !

          1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #7

            Then run your application through the debugger.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            AlvaroSA 1 Reply Last reply
            0
            • SGaistS SGaist

              Then run your application through the debugger.

              AlvaroSA Offline
              AlvaroSA Offline
              AlvaroS
              wrote on last edited by
              #8

              @SGaist Now I do this:

                  QString program = "./home/princi";
                  QStringList arguments;
              
                  arguments << "0" << QString::number(wps.front().x()) << QString::number(wps.front().y()) << "0" << QString::number(wps.back().x()) << QString::number(wps.back().y()) << "prueba_princi.bmp" << "0 0 +" ;
              
                  QProcess myProcess;
              
                  myProcess.start(program,arguments);
              

              it compiles good but my application does not run...

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #9

                You call it with a path relative to where you main application is started.

                ./home/princi is equivalent to $PWD/home/princi/ which is likely not what you want, is it ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                AlvaroSA 2 Replies Last reply
                2
                • SGaistS SGaist

                  You call it with a path relative to where you main application is started.

                  ./home/princi is equivalent to $PWD/home/princi/ which is likely not what you want, is it ?

                  AlvaroSA Offline
                  AlvaroSA Offline
                  AlvaroS
                  wrote on last edited by
                  #10

                  @SGaist yes! but it does not run with that code..

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    You call it with a path relative to where you main application is started.

                    ./home/princi is equivalent to $PWD/home/princi/ which is likely not what you want, is it ?

                    AlvaroSA Offline
                    AlvaroSA Offline
                    AlvaroS
                    wrote on last edited by
                    #11

                    @SGaist Now I do this and nothing as well..

                        QString program = "princi";
                        QStringList arguments;
                    
                        arguments << "0" << QString::number(wps.front().x()) << QString::number(wps.front().y()) << "0" << QString::number(wps.back().x()) << QString::number(wps.back().y()) << "prueba_princi.bmp" << "0 0 +" ;
                    
                        QString folder = "/home/";
                    
                        QProcess *myProcess = new QProcess(this);
                    
                        myProcess->setWorkingDirectory(folder);
                    
                        myProcess->start(program,arguments);
                    
                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      What is the full path to princi ? And what is the full path to your application ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      AlvaroSA 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        What is the full path to princi ? And what is the full path to your application ?

                        AlvaroSA Offline
                        AlvaroSA Offline
                        AlvaroS
                        wrote on last edited by
                        #13

                        @SGaist Full path of princi (which is the executable) is /home/
                        and full path of my QT aplication is /home/workspace

                        1 Reply Last reply
                        0
                        • jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          /home is not the full path to your application except it is called home and is located in the root directory.
                          So, you can start the program in a shell with /home/princi?
                          Did you try it?
                          This is quite strange path: in /home you usually have a directory for each user and /home is not writable by normal user.

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

                          AlvaroSA 1 Reply Last reply
                          2
                          • jsulmJ jsulm

                            /home is not the full path to your application except it is called home and is located in the root directory.
                            So, you can start the program in a shell with /home/princi?
                            Did you try it?
                            This is quite strange path: in /home you usually have a directory for each user and /home is not writable by normal user.

                            AlvaroSA Offline
                            AlvaroSA Offline
                            AlvaroS
                            wrote on last edited by
                            #15

                            @jsulm sorry yes, it is in /home/user1/ but it does not run as well...

                            1 Reply Last reply
                            0
                            • mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #16

                              @AlvaroS said:

                              QString program = "princi";

                              should be

                              QString program = "/home/user1/princi";

                              ?

                              AlvaroSA 1 Reply Last reply
                              1
                              • mrjjM mrjj

                                @AlvaroS said:

                                QString program = "princi";

                                should be

                                QString program = "/home/user1/princi";

                                ?

                                AlvaroSA Offline
                                AlvaroSA Offline
                                AlvaroS
                                wrote on last edited by
                                #17

                                @mrjj It works in the same way... :(

                                jsulmJ mrjjM 2 Replies Last reply
                                0
                                • AlvaroSA AlvaroS

                                  @mrjj It works in the same way... :(

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

                                  @AlvaroS So, if you enter /home/user1/princi in a terminal window and press enter it does not start? What happens? Any error message?

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

                                  AlvaroSA 1 Reply Last reply
                                  1
                                  • AlvaroSA AlvaroS

                                    @mrjj It works in the same way... :(

                                    mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #19

                                    @AlvaroS

                                    Ok, you must debug then
                                    try to use
                                    http://doc.qt.io/qt-5/qprocess.html#error
                                    to see what it thinks.

                                    AlvaroSA 1 Reply Last reply
                                    2
                                    • jsulmJ jsulm

                                      @AlvaroS So, if you enter /home/user1/princi in a terminal window and press enter it does not start? What happens? Any error message?

                                      AlvaroSA Offline
                                      AlvaroSA Offline
                                      AlvaroS
                                      wrote on last edited by
                                      #20

                                      @jsulm In a terminal if I write

                                      ./princi 0 747.37 427.68 0 844.37 42.54 prueba_princi.bmp 0 0 +
                                      

                                      in /home/user1/ directory it runs good

                                      jsulmJ AlvaroSA 2 Replies Last reply
                                      0
                                      • AlvaroSA AlvaroS

                                        @jsulm In a terminal if I write

                                        ./princi 0 747.37 427.68 0 844.37 42.54 prueba_princi.bmp 0 0 +
                                        

                                        in /home/user1/ directory it runs good

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

                                        @AlvaroS Then try what @mrjj suggested

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

                                        1 Reply Last reply
                                        0
                                        • mrjjM mrjj

                                          @AlvaroS

                                          Ok, you must debug then
                                          try to use
                                          http://doc.qt.io/qt-5/qprocess.html#error
                                          to see what it thinks.

                                          AlvaroSA Offline
                                          AlvaroSA Offline
                                          AlvaroS
                                          wrote on last edited by
                                          #22
                                          This post is deleted!
                                          mrjjM 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