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. Qt pushButton trigger terminal command
Forum Updated to NodeBB v4.3 + New Features

Qt pushButton trigger terminal command

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.7k 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.
  • F Offline
    F Offline
    frodi
    wrote on 6 Nov 2018, 11:50 last edited by
    #1

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

    J 1 Reply Last reply 6 Nov 2018, 12:08
    0
    • F frodi
      6 Nov 2018, 11:50

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

      J Offline
      J Offline
      JonB
      wrote on 6 Nov 2018, 12:08 last edited by
      #2

      @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
      3
      • F Offline
        F Offline
        frodi
        wrote on 6 Nov 2018, 13:28 last edited by
        #3

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

        J J 2 Replies Last reply 6 Nov 2018, 14:04
        0
        • F frodi
          6 Nov 2018, 13:28

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

          J Offline
          J Offline
          JonB
          wrote on 6 Nov 2018, 14:04 last edited by
          #4

          @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
          3
          • F frodi
            6 Nov 2018, 13:28

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

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 7 Nov 2018, 06:12 last edited by
            #5

            @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 7 Nov 2018, 08:34
            1
            • J jsulm
              7 Nov 2018, 06:12

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

              F Offline
              F Offline
              frodi
              wrote on 7 Nov 2018, 08:34 last edited by
              #6

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

              J 1 Reply Last reply 7 Nov 2018, 08:39
              0
              • F frodi
                7 Nov 2018, 08:34

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

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 7 Nov 2018, 08:39 last edited by
                #7

                @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

                J 1 Reply Last reply 7 Nov 2018, 08:45
                0
                • J jsulm
                  7 Nov 2018, 08:39

                  @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);
                  
                  J Offline
                  J Offline
                  JonB
                  wrote on 7 Nov 2018, 08:45 last edited by JonB 11 Jul 2018, 08:48
                  #8

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

                  4/8

                  6 Nov 2018, 14:04

                  • Login

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