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

QProcess cmd & tptf

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 3.4k 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.
  • B Bruschetta

    @Bruschetta Tryied this way too, but nothing changed

     QProcess process;
        QString program = "cmd"; //used cmd.exe too,nothing .. 
        QStringList arguments = QStringList();
    
        arguments<< "tftp";
        arguments<< "-i";
        arguments<< "192.168.2.1";
        arguments<< "get";
        arguments<< "configINPUT.txt";
        process.setWorkingDirectory(temp_path);
        process.start(program,arguments);
        qDebug()<<arguments;
        process.waitForFinished();
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #3

    @Bruschetta
    Why are you using cmd at all? Do you really need to use start? How does a simple:

    process.start("tftp -i 192.168.2.1 get configINPUT.txt");
    

    or

        QString program = "tftp"; 
        QStringList arguments = QStringList();
    
        arguments<< "-i";
        ...
    

    not work right? (BTW, your existing second attempt won't work at all because you running a cmd without the /c.)

    Also, do you understand what any kind of process.waitForFinished(); will do if you do use start?? (I mean the cmd /c start ..., not the process.start.)

    process.start("cmd.exe /C start C:/Users/user/Desktop/configINPUT.txt");

    I wouldn't hold your breath that any of these OS commands are guaranteed to work when you pass a file path using the Qt internal / separators. make sure you use \s when you pass to OS. Use http://doc.qt.io/qt-5/qdir.html#toNativeSeparators if necessary on your paths.

    B 1 Reply Last reply
    2
    • JonBJ JonB

      @Bruschetta
      Why are you using cmd at all? Do you really need to use start? How does a simple:

      process.start("tftp -i 192.168.2.1 get configINPUT.txt");
      

      or

          QString program = "tftp"; 
          QStringList arguments = QStringList();
      
          arguments<< "-i";
          ...
      

      not work right? (BTW, your existing second attempt won't work at all because you running a cmd without the /c.)

      Also, do you understand what any kind of process.waitForFinished(); will do if you do use start?? (I mean the cmd /c start ..., not the process.start.)

      process.start("cmd.exe /C start C:/Users/user/Desktop/configINPUT.txt");

      I wouldn't hold your breath that any of these OS commands are guaranteed to work when you pass a file path using the Qt internal / separators. make sure you use \s when you pass to OS. Use http://doc.qt.io/qt-5/qdir.html#toNativeSeparators if necessary on your paths.

      B Offline
      B Offline
      Bruschetta
      wrote on last edited by
      #4

      @JonB
      Reading your reply i tryed to use /C param with the cmd but with no luck

       QProcess process;
          QString program = "cmd.exe";
          QStringList arguments = QStringList();
      
          arguments<< "/C";
          arguments<< "tftp";
          arguments<< "-i";
          arguments<< "192.168.2.1";
          arguments<< "get";
          arguments<< "configINPUT.txt";
          bool ret= process.startDetached(program,arguments);
          qDebug() << arguments;
          qDebug() << ret;
      

      Then i tryed to avoid using cmd at all

       QProcess process;
          QString program = "tftp.exe";
          QStringList arguments = QStringList();
      
          arguments<< "/C";
          arguments<< "-i";
          arguments<< "192.168.2.1";
          arguments<< "get";
          arguments<< "configINPUT.txt";
          bool ret= process.startDetached(program,arguments);
          qDebug() << arguments;
          qDebug() << ret;
      

      But the result it's the same,not working

      JonBJ 1 Reply Last reply
      0
      • B Bruschetta

        @JonB
        Reading your reply i tryed to use /C param with the cmd but with no luck

         QProcess process;
            QString program = "cmd.exe";
            QStringList arguments = QStringList();
        
            arguments<< "/C";
            arguments<< "tftp";
            arguments<< "-i";
            arguments<< "192.168.2.1";
            arguments<< "get";
            arguments<< "configINPUT.txt";
            bool ret= process.startDetached(program,arguments);
            qDebug() << arguments;
            qDebug() << ret;
        

        Then i tryed to avoid using cmd at all

         QProcess process;
            QString program = "tftp.exe";
            QStringList arguments = QStringList();
        
            arguments<< "/C";
            arguments<< "-i";
            arguments<< "192.168.2.1";
            arguments<< "get";
            arguments<< "configINPUT.txt";
            bool ret= process.startDetached(program,arguments);
            qDebug() << arguments;
            qDebug() << ret;
        

        But the result it's the same,not working

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #5

        @Bruschetta
        But in your second example you are still passing "/C" argument, this time to tftp, which does not accept it.

        What happens with a completely plain:

        process.start("tftp -i 192.168.2.1 get configINPUT.txt");
        

        ?

        What does "not working" even mean? How are you judging it's not working? What does qDebug() << ret; print? Why are you using startDetached now? Is your file argument actually, literally, character-for-character as you show here, or is it something else? You have never stated that you have tested the exact tftp outside of Qt and it's working?

        B 2 Replies Last reply
        1
        • JonBJ JonB

          @Bruschetta
          But in your second example you are still passing "/C" argument, this time to tftp, which does not accept it.

          What happens with a completely plain:

          process.start("tftp -i 192.168.2.1 get configINPUT.txt");
          

          ?

          What does "not working" even mean? How are you judging it's not working? What does qDebug() << ret; print? Why are you using startDetached now? Is your file argument actually, literally, character-for-character as you show here, or is it something else? You have never stated that you have tested the exact tftp outside of Qt and it's working?

          B Offline
          B Offline
          Bruschetta
          wrote on last edited by
          #6

          @JonB
          Not working because the plain command in cmd is working well with the device i'm connected with.
          Another 3rdparty program is able to exchange data with the device and tftp.

          qDebug() << ret; returns TRUE if i use

          QProcess process;
              QString program = "cmd.exe";
              QStringList arguments = QStringList();
          
              arguments<< "/C";
              arguments<< "tftp";
              arguments<< "-i";
              arguments<< "192.168.2.1";
              arguments<< "get";
              arguments<< "configINPUT.txt";
              bool ret= process.startDetached(program,arguments);
              qDebug() << arguments;
              qDebug() << ret;
          

          Otherwise it returns FALSE. But true or false is not giving me "any" hints , the file is not taken from the device even if ret is TRUE.

          The /C in the second example is a typo, wrong cut and paste.
          Anyway i appreciate the time you are spending to give me answers

          1 Reply Last reply
          0
          • JonBJ JonB

            @Bruschetta
            But in your second example you are still passing "/C" argument, this time to tftp, which does not accept it.

            What happens with a completely plain:

            process.start("tftp -i 192.168.2.1 get configINPUT.txt");
            

            ?

            What does "not working" even mean? How are you judging it's not working? What does qDebug() << ret; print? Why are you using startDetached now? Is your file argument actually, literally, character-for-character as you show here, or is it something else? You have never stated that you have tested the exact tftp outside of Qt and it's working?

            B Offline
            B Offline
            Bruschetta
            wrote on last edited by
            #7

            @JonB
            What happens with a completely plain:

            process.start("tftp -i 192.168.2.1 get configINPUT.txt");

            ?

            Nothing, unfortunately :(

            JonBJ 1 Reply Last reply
            0
            • B Bruschetta

              @JonB
              What happens with a completely plain:

              process.start("tftp -i 192.168.2.1 get configINPUT.txt");

              ?

              Nothing, unfortunately :(

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #8

              @Bruschetta
              Well, if that command works as-is outside of Qt, and assuming tftp is a .exe and not a .bat file, I really reckon it will work same via process.start()....

              You still have not explained how you know "nothing" is happening....

              B 1 Reply Last reply
              0
              • JonBJ JonB

                @Bruschetta
                Well, if that command works as-is outside of Qt, and assuming tftp is a .exe and not a .bat file, I really reckon it will work same via process.start()....

                You still have not explained how you know "nothing" is happening....

                B Offline
                B Offline
                Bruschetta
                wrote on last edited by
                #9

                @JonB
                Nothing is happening means that the plain command i launch from cmd creates the file i get from the device at the 192.168.2.1 address. The commands that are cast by the QProcess are not working because there are no new files.

                JonBJ jsulmJ 2 Replies Last reply
                0
                • B Bruschetta

                  @JonB
                  Nothing is happening means that the plain command i launch from cmd creates the file i get from the device at the 192.168.2.1 address. The commands that are cast by the QProcess are not working because there are no new files.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #10

                  @Bruschetta
                  I'm guessing that your command line will cause the file to be gotten to the current directory when you launch it from a command-prompt --- is that right? Have you considered, for example, whether the current directory is the same when you launch (presumably) by opening a command prompt interactively and typing it in versus what it is when you spawn a QProcess from within your Qt (maybe UI) application?

                  I know it's more work, but at some point to make your code robust you will need/ought to capture stdout & stderr from QProcess (it's all in that documentation), and do something with it, like maybe show it to the user. If you did so now, you would perhaps discover why "nothing happens" --- often you'll find there's an error message, e.g. from your tptf, and that would explain why you're not seeing the expected behaviour.

                  1 Reply Last reply
                  1
                  • B Bruschetta

                    @JonB
                    Nothing is happening means that the plain command i launch from cmd creates the file i get from the device at the 192.168.2.1 address. The commands that are cast by the QProcess are not working because there are no new files.

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

                    @Bruschetta Is tftp.exe in your PATH? If not then it is simply not found.
                    Did you try to connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred and print the error?

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

                    B 1 Reply Last reply
                    3
                    • jsulmJ jsulm

                      @Bruschetta Is tftp.exe in your PATH? If not then it is simply not found.
                      Did you try to connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred and print the error?

                      B Offline
                      B Offline
                      Bruschetta
                      wrote on last edited by Bruschetta
                      #12

                      @jsulm
                      Yes, tftp.exe is in my path.
                      EDIT
                      I get error enum val = QProcess::ProcessError(FailedToStart) Error using
                      QString program = "C:/Windows/System32/TFTP.exe"; or
                      QString program = "C:\Windows\System32\TFTP.exe"; or
                      QString program = "TFTP.exe"; or
                      QString program = "TFTP.";

                          QString path = QDir::current().absolutePath();
                          QString program = "C:\\Windows\\System32\\TFTP.exe";
                          QStringList arguments = QStringList();
                          arguments<< "-i";
                          arguments<< "192.168.2.2";
                          arguments<< "get";
                          arguments<< "configINPUT.txt";
                          QProcess process;
                      
                          connect(&process, &QProcess::errorOccurred, [=](QProcess::ProcessError error)
                          {
                              qDebug() << "error enum val = " << error << endl;
                          });
                          process.setProgram(program);
                          process.setArguments(arguments);
                          process.setWorkingDirectory(path);
                          process.start();
                      
                      JonBJ 1 Reply Last reply
                      0
                      • B Bruschetta

                        @jsulm
                        Yes, tftp.exe is in my path.
                        EDIT
                        I get error enum val = QProcess::ProcessError(FailedToStart) Error using
                        QString program = "C:/Windows/System32/TFTP.exe"; or
                        QString program = "C:\Windows\System32\TFTP.exe"; or
                        QString program = "TFTP.exe"; or
                        QString program = "TFTP.";

                            QString path = QDir::current().absolutePath();
                            QString program = "C:\\Windows\\System32\\TFTP.exe";
                            QStringList arguments = QStringList();
                            arguments<< "-i";
                            arguments<< "192.168.2.2";
                            arguments<< "get";
                            arguments<< "configINPUT.txt";
                            QProcess process;
                        
                            connect(&process, &QProcess::errorOccurred, [=](QProcess::ProcessError error)
                            {
                                qDebug() << "error enum val = " << error << endl;
                            });
                            process.setProgram(program);
                            process.setArguments(arguments);
                            process.setWorkingDirectory(path);
                            process.start();
                        
                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #13

                        @Bruschetta

                        1. Are you sure "C:\Windows\System32\TFTP.exe" is the right path?
                        2. Is you Qt app compiled as 64-bit or 32-bit?
                        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
                        • Unsolved