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. startDetached with cmd how to close it automaticlly ??

startDetached with cmd how to close it automaticlly ??

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 5 Posters 2.5k 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.
  • mrjjM mrjj

    Hi
    I dont think its possible to close an already open cmd prompt ( keept open with K)
    , by runner another cmd.exe.
    Why not use /C in all places ?

    R Offline
    R Offline
    RiceBall
    wrote on last edited by
    #8

    @mrjj said in startDetached with cmd how to close it automaticlly ??:

    Hi
    I dont think its possible to close an already open cmd prompt ( keept open with K)
    , by runner another cmd.exe.
    Why not use /C in all places ?

    How could I fix it by /C ??
    Do I use it correctly ??

    1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      I dont think its possible to close an already open cmd prompt ( keept open with K)
      , by runner another cmd.exe.
      Why not use /C in all places ?

      R Offline
      R Offline
      RiceBall
      wrote on last edited by
      #9

      @mrjj said in startDetached with cmd how to close it automaticlly ??:

      Hi
      I dont think its possible to close an already open cmd prompt ( keept open with K)
      , by runner another cmd.exe.
      Why not use /C in all places ?

         QString  DOS( "cmd.exe " );
      
         foreach(QFileInfo mitm, mDir.entryInfoList(Qfilter))   
         {
      
             QStringList params = QStringList() << "/C" << "frtomem -p WnaYooAQ " << mitm.fileName() ;
             QProcess::startDetached( DOS,  params );   
         }
      

      I have tried to fix it by /C
      But the problem is the same.

      jsulmJ 1 Reply Last reply
      0
      • R RiceBall

        @mrjj said in startDetached with cmd how to close it automaticlly ??:

        Hi
        I dont think its possible to close an already open cmd prompt ( keept open with K)
        , by runner another cmd.exe.
        Why not use /C in all places ?

           QString  DOS( "cmd.exe " );
        
           foreach(QFileInfo mitm, mDir.entryInfoList(Qfilter))   
           {
        
               QStringList params = QStringList() << "/C" << "frtomem -p WnaYooAQ " << mitm.fileName() ;
               QProcess::startDetached( DOS,  params );   
           }
        

        I have tried to fix it by /C
        But the problem is the same.

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

        @RiceBall Just tried on my Windows 10 machine with "dir" command - works as expected.
        You're using QProcess wrongly.
        It should be:

        QStringList params = QStringList() << "/C" << "frtomem" << "-p" << "WnaYooAQ" << mitm.fileName() ;
        QProcess::startDetached( DOS,  params );
        

        So, each parameter must be passed as a dedicated string, not all parameters in one string!

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

        R 1 Reply Last reply
        1
        • jsulmJ jsulm

          @RiceBall Just tried on my Windows 10 machine with "dir" command - works as expected.
          You're using QProcess wrongly.
          It should be:

          QStringList params = QStringList() << "/C" << "frtomem" << "-p" << "WnaYooAQ" << mitm.fileName() ;
          QProcess::startDetached( DOS,  params );
          

          So, each parameter must be passed as a dedicated string, not all parameters in one string!

          R Offline
          R Offline
          RiceBall
          wrote on last edited by
          #11

          @jsulm said in startDetached with cmd how to close it automaticlly ??:

          @RiceBall Just tried on my Windows 10 machine with "dir" command - works as expected.
          You're using QProcess wrongly.
          It should be:

          QStringList params = QStringList() << "/C" << "frtomem" << "-p" << "WnaYooAQ" << mitm.fileName() ;
          QProcess::startDetached( DOS,  params );
          

          So, each parameter must be passed as a dedicated string, not all parameters in one string!

          I tried to fix it by your recommend.
          But it also can't close by itself.
          0_1557725937550_final result.gif

          jsulmJ 1 Reply Last reply
          0
          • R RiceBall

            @jsulm said in startDetached with cmd how to close it automaticlly ??:

            @RiceBall Just tried on my Windows 10 machine with "dir" command - works as expected.
            You're using QProcess wrongly.
            It should be:

            QStringList params = QStringList() << "/C" << "frtomem" << "-p" << "WnaYooAQ" << mitm.fileName() ;
            QProcess::startDetached( DOS,  params );
            

            So, each parameter must be passed as a dedicated string, not all parameters in one string!

            I tried to fix it by your recommend.
            But it also can't close by itself.
            0_1557725937550_final result.gif

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

            @RiceBall To me it looks like the command you're calling does not finish and that's why terminal window is not closed.

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

            R 1 Reply Last reply
            0
            • jsulmJ jsulm

              @RiceBall To me it looks like the command you're calling does not finish and that's why terminal window is not closed.

              R Offline
              R Offline
              RiceBall
              wrote on last edited by
              #13

              @jsulm said in startDetached with cmd how to close it automaticlly ??:

              @RiceBall To me it looks like the command you're calling does not finish and that's why terminal window is not closed.

              Could I set timer to close it forcely??

              jsulmJ J.HilkJ 2 Replies Last reply
              0
              • R RiceBall

                @jsulm said in startDetached with cmd how to close it automaticlly ??:

                @RiceBall To me it looks like the command you're calling does not finish and that's why terminal window is not closed.

                Could I set timer to close it forcely??

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

                @RiceBall You should first check the documentation of that command. Maybe you just need to provide a parameter to it so it closes when finished.
                If you want to abort it forcefully you should not use startDetached.

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

                1 Reply Last reply
                0
                • R RiceBall

                  @jsulm said in startDetached with cmd how to close it automaticlly ??:

                  @RiceBall To me it looks like the command you're calling does not finish and that's why terminal window is not closed.

                  Could I set timer to close it forcely??

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by J.Hilk
                  #15

                  @RiceBall are you sure, the terminal you're seeing is actually the one started by QProcess ?

                  I think you're writing a terminal app yourself. And you're calling a.exec(); on your QCoreApplication -> it's not going to close itself


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  R 1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @RiceBall are you sure, the terminal you're seeing is actually the one started by QProcess ?

                    I think you're writing a terminal app yourself. And you're calling a.exec(); on your QCoreApplication -> it's not going to close itself

                    R Offline
                    R Offline
                    RiceBall
                    wrote on last edited by
                    #16

                    @J.Hilk @jsulm
                    said in startDetached with cmd how to close it automaticlly ??:

                    @RiceBall are you sure, the terminal you're seeing is actually the one started by QProcess ?

                    I think you're writing a terminal app yourself. And you're calling a.exec(); on your QCoreApplication -> it's not going to close itself

                    I try to simple it.
                    I fix it by ping 1.1.1.1 .
                    But it is also not success.

                    int main(int argc, char *argv[])
                    {
                        QCoreApplication a(argc, argv);
                    
                    
                           QString  DOS( "cmd.exe " );
                           QStringList params = QStringList() << "/C" << "ping" << "1.1.1.1" ;
                           QProcess::startDetached( DOS,  params ); 
                           return a.exec();
                    }
                    
                    

                    If I can not use startDetached.
                    Do you have any recommend I can use ??

                    0_1557730436772_final result.gif

                    jsulmJ 1 Reply Last reply
                    0
                    • R RiceBall

                      @J.Hilk @jsulm
                      said in startDetached with cmd how to close it automaticlly ??:

                      @RiceBall are you sure, the terminal you're seeing is actually the one started by QProcess ?

                      I think you're writing a terminal app yourself. And you're calling a.exec(); on your QCoreApplication -> it's not going to close itself

                      I try to simple it.
                      I fix it by ping 1.1.1.1 .
                      But it is also not success.

                      int main(int argc, char *argv[])
                      {
                          QCoreApplication a(argc, argv);
                      
                      
                             QString  DOS( "cmd.exe " );
                             QStringList params = QStringList() << "/C" << "ping" << "1.1.1.1" ;
                             QProcess::startDetached( DOS,  params ); 
                             return a.exec();
                      }
                      
                      

                      If I can not use startDetached.
                      Do you have any recommend I can use ??

                      0_1557730436772_final result.gif

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

                      @RiceBall Is your app of type "console" (CONFIG += console in pro file)? If so then the terminal window you see is the one of your app and will be closed when you close your app. So, I don't see what the problem is in this case? @J-Hilk already pointed out this.
                      My widgets app does not show any terminal when I execute command like you do - because it is not a console app.

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

                      R 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @RiceBall Is your app of type "console" (CONFIG += console in pro file)? If so then the terminal window you see is the one of your app and will be closed when you close your app. So, I don't see what the problem is in this case? @J-Hilk already pointed out this.
                        My widgets app does not show any terminal when I execute command like you do - because it is not a console app.

                        R Offline
                        R Offline
                        RiceBall
                        wrote on last edited by
                        #18

                        @jsulm said in startDetached with cmd how to close it automaticlly ??:

                        @RiceBall Is your app of type "console" (CONFIG += console in pro file)? If so then the terminal window you see is the one of your app and will be closed when you close your app. So, I don't see what the problem is in this case? @J-Hilk already pointed out this.
                        My widgets app does not show any terminal when I execute command like you do - because it is not a console app.

                        Sorry, Maybe I don't explain it very clear.
                        Actually,I make it by console.It is right.
                        I want to show some information for user.
                        When finished , I want to close APP or terminal window automatically.

                        jsulmJ 1 Reply Last reply
                        0
                        • R RiceBall

                          @jsulm said in startDetached with cmd how to close it automaticlly ??:

                          @RiceBall Is your app of type "console" (CONFIG += console in pro file)? If so then the terminal window you see is the one of your app and will be closed when you close your app. So, I don't see what the problem is in this case? @J-Hilk already pointed out this.
                          My widgets app does not show any terminal when I execute command like you do - because it is not a console app.

                          Sorry, Maybe I don't explain it very clear.
                          Actually,I make it by console.It is right.
                          I want to show some information for user.
                          When finished , I want to close APP or terminal window automatically.

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

                          @RiceBall Yes, you did not explain well. Don't use startDetached (use the "normal" start()). Use https://doc.qt.io/qt-5/qprocess.html#finished signal and in the slot call https://doc.qt.io/qt-5/qcoreapplication.html#exit.

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

                          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