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. command prompt command execution in Qt
Forum Update on Monday, May 27th 2025

command prompt command execution in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 12.5k Views
  • 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.
  • P Offline
    P Offline
    Pranit Patil
    wrote on 17 Aug 2018, 10:17 last edited by
    #1

    How command prompt command execution in Qt application

    like in case of - gedit my.txt in command prompt my.txt file be open to edit
    in case of - mkdir Qt in command prompt i have to execute this command and want to create folder

    Thank you in Advance.

    @Embedded Software Developer
    God has given you one face, and you make yourself another.

    P J 2 Replies Last reply 17 Aug 2018, 10:26
    0
    • P Pranit Patil
      17 Aug 2018, 10:17

      How command prompt command execution in Qt application

      like in case of - gedit my.txt in command prompt my.txt file be open to edit
      in case of - mkdir Qt in command prompt i have to execute this command and want to create folder

      Thank you in Advance.

      P Offline
      P Offline
      Pranit Patil
      wrote on 17 Aug 2018, 10:26 last edited by
      #2

      Any one here ?

      @Embedded Software Developer
      God has given you one face, and you make yourself another.

      J 1 Reply Last reply 17 Aug 2018, 10:32
      0
      • P Pranit Patil
        17 Aug 2018, 10:17

        How command prompt command execution in Qt application

        like in case of - gedit my.txt in command prompt my.txt file be open to edit
        in case of - mkdir Qt in command prompt i have to execute this command and want to create folder

        Thank you in Advance.

        J Offline
        J Offline
        JonB
        wrote on 17 Aug 2018, 10:31 last edited by JonB
        #3

        @Pranit-Patil

        QProcess::execute("gedit my.txt")

        QProcess::execute("mkdir folder")

        In practice you should probably use the http://doc.qt.io/qt-5/qprocess.html#execute overload to pass the argument(s) as a QStringList.

        P.S.
        To create a folder, don't actually use a sub-process of mkdir, use the in-built Qt function for creating a directory.

        P 1 Reply Last reply 17 Aug 2018, 10:36
        4
        • P Pranit Patil
          17 Aug 2018, 10:26

          Any one here ?

          J Offline
          J Offline
          JonB
          wrote on 17 Aug 2018, 10:32 last edited by JonB
          #4

          @Pranit-Patil said in command prompt command execution in Qt:

          Any one here ?

          You posted that 9 minutes after your original query. Do you pay for my support, or anyone else's, within 10 minutes? :( Or do you just think it's my/our duty? In which case I'll leave it to others for you from now on...

          1 Reply Last reply
          1
          • J JonB
            17 Aug 2018, 10:31

            @Pranit-Patil

            QProcess::execute("gedit my.txt")

            QProcess::execute("mkdir folder")

            In practice you should probably use the http://doc.qt.io/qt-5/qprocess.html#execute overload to pass the argument(s) as a QStringList.

            P.S.
            To create a folder, don't actually use a sub-process of mkdir, use the in-built Qt function for creating a directory.

            P Offline
            P Offline
            Pranit Patil
            wrote on 17 Aug 2018, 10:36 last edited by
            #5

            @JonB
            i m doing simply like this but not getting o/p

            QProcess process;
            QString exePath = "C:/Windows/ystem32/cmd.exe";
            process.start(exePath);
            process.execute("cmd.exe");

            @Embedded Software Developer
            God has given you one face, and you make yourself another.

            J 1 Reply Last reply 17 Aug 2018, 10:38
            0
            • P Pranit Patil
              17 Aug 2018, 10:36

              @JonB
              i m doing simply like this but not getting o/p

              QProcess process;
              QString exePath = "C:/Windows/ystem32/cmd.exe";
              process.start(exePath);
              process.execute("cmd.exe");

              J Offline
              J Offline
              JonB
              wrote on 17 Aug 2018, 10:38 last edited by JonB
              #6

              @Pranit-Patil
              I gave you the lines to type for your question. If you choose to do something quite different and wrong, that's up to you. Perhaps others will sort you out.

              P 1 Reply Last reply 17 Aug 2018, 10:43
              0
              • J JonB
                17 Aug 2018, 10:38

                @Pranit-Patil
                I gave you the lines to type for your question. If you choose to do something quite different and wrong, that's up to you. Perhaps others will sort you out.

                P Offline
                P Offline
                Pranit Patil
                wrote on 17 Aug 2018, 10:43 last edited by
                #7

                @JonB sorry for that

                i tried your examples
                QProcess::execute("gedit my.txt");
                QProcess::execute("mkdir Test");

                but not getting any error or any output.

                @Embedded Software Developer
                God has given you one face, and you make yourself another.

                J 1 Reply Last reply 17 Aug 2018, 11:01
                0
                • P Pranit Patil
                  17 Aug 2018, 10:43

                  @JonB sorry for that

                  i tried your examples
                  QProcess::execute("gedit my.txt");
                  QProcess::execute("mkdir Test");

                  but not getting any error or any output.

                  J Offline
                  J Offline
                  JonB
                  wrote on 17 Aug 2018, 11:01 last edited by JonB
                  #8

                  @Pranit-Patil

                  Neither command should produce any error or output. Unless you don't even have gedit.... And if you're Windows (your question does not even mention the OS), you may need QProcess::execute("cmd /c mkdir Test");.

                  P 1 Reply Last reply 17 Aug 2018, 11:45
                  2
                  • J JonB
                    17 Aug 2018, 11:01

                    @Pranit-Patil

                    Neither command should produce any error or output. Unless you don't even have gedit.... And if you're Windows (your question does not even mention the OS), you may need QProcess::execute("cmd /c mkdir Test");.

                    P Offline
                    P Offline
                    Pranit Patil
                    wrote on 17 Aug 2018, 11:45 last edited by
                    #9

                    @JonB Im Developing application in Qt creator 4.6.0 on windows 7 -32bit

                    #include <QProcess>
                    #include <QDir>
                    void Command::on_pushButton_clicked()
                    {
                    QProcess process;
                    QString exePath1 = "D:/Phoenix";
                    process.start(exePath1);
                    process.execute("cmd /c mkdir test");
                    }
                    not getting any output.

                    @Embedded Software Developer
                    God has given you one face, and you make yourself another.

                    J 1 Reply Last reply 17 Aug 2018, 11:53
                    0
                    • P Pranit Patil
                      17 Aug 2018, 11:45

                      @JonB Im Developing application in Qt creator 4.6.0 on windows 7 -32bit

                      #include <QProcess>
                      #include <QDir>
                      void Command::on_pushButton_clicked()
                      {
                      QProcess process;
                      QString exePath1 = "D:/Phoenix";
                      process.start(exePath1);
                      process.execute("cmd /c mkdir test");
                      }
                      not getting any output.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 17 Aug 2018, 11:53 last edited by jsulm
                      #10

                      @Pranit-Patil "not getting any output." - what "output" do you expect?
                      Why do you start new process to create a directory? You can do this way faster and easier with Qt (http://doc.qt.io/qt-5/qdir.html#mkdir)
                      Also this does not make any sense:

                      QProcess process;
                      QString exePath1 = "D:/Phoenix";
                      process.start(exePath1);
                      process.execute("cmd /c mkdir test");
                      

                      You can't start a directory as it is not an executable. There is no need to use both start() AND execute().
                      Did you actually read QProcess documentation?!
                      It has a nice example:

                      QString program = "./path/to/Qt/examples/widgets/analogclock";
                      QStringList arguments;
                      arguments << "-style" << "fusion";
                      
                      QProcess *myProcess = new QProcess(parent);
                      myProcess->start(program, arguments);
                      

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

                      J 1 Reply Last reply 17 Aug 2018, 11:59
                      4
                      • J jsulm
                        17 Aug 2018, 11:53

                        @Pranit-Patil "not getting any output." - what "output" do you expect?
                        Why do you start new process to create a directory? You can do this way faster and easier with Qt (http://doc.qt.io/qt-5/qdir.html#mkdir)
                        Also this does not make any sense:

                        QProcess process;
                        QString exePath1 = "D:/Phoenix";
                        process.start(exePath1);
                        process.execute("cmd /c mkdir test");
                        

                        You can't start a directory as it is not an executable. There is no need to use both start() AND execute().
                        Did you actually read QProcess documentation?!
                        It has a nice example:

                        QString program = "./path/to/Qt/examples/widgets/analogclock";
                        QStringList arguments;
                        arguments << "-style" << "fusion";
                        
                        QProcess *myProcess = new QProcess(parent);
                        myProcess->start(program, arguments);
                        
                        J Offline
                        J Offline
                        JonB
                        wrote on 17 Aug 2018, 11:59 last edited by JonB
                        #11

                        @jsulm
                        I already pointed all this stuff to OP above.
                        Additionally, I also deliberately used QProcess::execute() in my examples for him to keep it down to one liners. Each time he has also added an additional QProcess::start(). I suggested he just copy my examples verbatim to avoid this, but we don't seem to be getting anywhere.... I'll leave it to you :)

                        P 2 Replies Last reply 17 Aug 2018, 12:16
                        1
                        • J JonB
                          17 Aug 2018, 11:59

                          @jsulm
                          I already pointed all this stuff to OP above.
                          Additionally, I also deliberately used QProcess::execute() in my examples for him to keep it down to one liners. Each time he has also added an additional QProcess::start(). I suggested he just copy my examples verbatim to avoid this, but we don't seem to be getting anywhere.... I'll leave it to you :)

                          P Offline
                          P Offline
                          Pranit Patil
                          wrote on 17 Aug 2018, 12:16 last edited by
                          #12

                          @JonB
                          Thank you for your reply
                          Sorry sir i didn't understand what your saying ..?

                          aim - create folder in my system using commands of cmd prompt in any location through QT application.

                          Im new in Qt i don't have more knowledge on it plz suggest

                          @Embedded Software Developer
                          God has given you one face, and you make yourself another.

                          1 Reply Last reply
                          0
                          • J JonB
                            17 Aug 2018, 11:59

                            @jsulm
                            I already pointed all this stuff to OP above.
                            Additionally, I also deliberately used QProcess::execute() in my examples for him to keep it down to one liners. Each time he has also added an additional QProcess::start(). I suggested he just copy my examples verbatim to avoid this, but we don't seem to be getting anywhere.... I'll leave it to you :)

                            P Offline
                            P Offline
                            Pranit Patil
                            wrote on 17 Aug 2018, 12:27 last edited by
                            #13

                            @JonB @jsulm its working now thank u so much sir.
                            and sorry that.

                            @Embedded Software Developer
                            God has given you one face, and you make yourself another.

                            1 Reply Last reply
                            0

                            5/13

                            17 Aug 2018, 10:36

                            topic:navigator.unread, 8
                            • Login

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