Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Qt pushButton trigger terminal command

    General and Desktop
    3
    8
    1020
    Loading More Posts
    • 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.
    • F
      frodi last edited by

      Hi. I am totally new to Qt.
      Is there any way that a Qt pushButton can trigger a terminal command? f.ex netcat?

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @frodi last edited by

        @frodi
        What is a "terminal command"? I see a Linux netcat program. Does it keep running after you start it? Does it write stdout?

        I assume you mean you want to use QProcess to run a command. The detail of having that invoked when a QPushButton is clicked is neither here nor there. You have to decide where you want its output to show, e.g. in an xterm or read in & displayed by your calling program, etc.

        1 Reply Last reply Reply Quote 3
        • F
          frodi last edited by

          Well, I am thinking of a scenario where i click a button an then a netcat command is executed in the linux terminal

          JonB jsulm 2 Replies Last reply Reply Quote 0
          • JonB
            JonB @frodi last edited by

            @frodi
            In what Linux terminal?

            Yours is a GUI application which has button, right? So there is no terminal. You have to create one to run the command in, which is why I mentioned xterm. If that is what you need.

            I answered a question like this months ago. Have a look at https://forum.qt.io/topic/93735/start-terminal-with-command-by-qprocess/17, where I tracked down xterm -e <program> <argument> <argument> as the QProcess command-line. Is that what you want?

            1 Reply Last reply Reply Quote 3
            • jsulm
              jsulm Lifetime Qt Champion @frodi last edited by

              @frodi You don't need a terminal to run executables (unless you really want to see a terminal for some reason).
              Simply use QProcess to execute the executables.

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

              F 1 Reply Last reply Reply Quote 1
              • F
                frodi @jsulm last edited by

                @jsulm I dont need to see the terminal. I just need to send a command via netcat. As I am totally new to this topic, could you give me an example of how i can use the command:

                echo '3b00010000001b010001000000120000013000002713000300030101' | xxd -r -p | nc 172.16.4.44 30013
                

                With the use of a QProcess?

                jsulm 1 Reply Last reply Reply Quote 0
                • jsulm
                  jsulm Lifetime Qt Champion @frodi last edited by

                  @frodi http://doc.qt.io/qt-5/qprocess.html

                  QString program = "sh";
                  QStringList arguments;
                  arguments << "-c" << "echo" << "'3b00010000001b010001000000120000013000002713000300030101'" << "|" << "xxd" << "-r" << "-p" << "|" << "nc" << "172.16.4.44 30013";
                  
                  QProcess myProcess;
                  myProcess.start(program, arguments);
                  

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

                  JonB 1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB @jsulm last edited by JonB

                    @jsulm
                    Although I admit I have not tried it, this does not look right. The syntax of /bin/sh (or /bin/bash) for a command is:

                    /bin/sh -c "single-argument-to--c-argument"
                    

                    You are passing each bit as a separate argument to bin/sh -c, which will surely go wrong at least depending on what is in the arguments (whitespace, quotes, pipe symbols, ...)...?

                    I would have expected something more like:

                    QString program = "/bin/sh";
                    QStringList arguments;
                    arguments << "-c" << "echo '3b00010000001b010001000000120000013000002713000300030101' | xxd -r -p | nc 172.16.4.44 30013"
                    
                    1 Reply Last reply Reply Quote 1
                    • Referenced by  Abderrahmene_Rayene Abderrahmene_Rayene 
                    • First post
                      Last post