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 Updated to NodeBB v4.3 + New Features

command prompt command execution in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 12.6k 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.
  • Pranit PatilP Pranit Patil

    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.

    JonBJ Online
    JonBJ Online
    JonB
    wrote on 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.

    Pranit PatilP 1 Reply Last reply
    4
    • Pranit PatilP Pranit Patil

      Any one here ?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on 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
      • JonBJ JonB

        @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.

        Pranit PatilP Offline
        Pranit PatilP Offline
        Pranit Patil
        wrote on 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.

        JonBJ 1 Reply Last reply
        0
        • Pranit PatilP Pranit Patil

          @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");

          JonBJ Online
          JonBJ Online
          JonB
          wrote on 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.

          Pranit PatilP 1 Reply Last reply
          0
          • JonBJ JonB

            @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.

            Pranit PatilP Offline
            Pranit PatilP Offline
            Pranit Patil
            wrote on 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.

            JonBJ 1 Reply Last reply
            0
            • Pranit PatilP Pranit Patil

              @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.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on 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");.

              Pranit PatilP 1 Reply Last reply
              2
              • JonBJ JonB

                @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");.

                Pranit PatilP Offline
                Pranit PatilP Offline
                Pranit Patil
                wrote on 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.

                jsulmJ 1 Reply Last reply
                0
                • Pranit PatilP Pranit Patil

                  @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.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 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

                  JonBJ 1 Reply Last reply
                  4
                  • jsulmJ jsulm

                    @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);
                    
                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on 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 :)

                    Pranit PatilP 2 Replies Last reply
                    1
                    • JonBJ JonB

                      @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 :)

                      Pranit PatilP Offline
                      Pranit PatilP Offline
                      Pranit Patil
                      wrote on 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
                      • JonBJ JonB

                        @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 :)

                        Pranit PatilP Offline
                        Pranit PatilP Offline
                        Pranit Patil
                        wrote on 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

                        • Login

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