Qt pushButton trigger terminal command
Hi. I am totally new to Qt.
Is there any way that a Qt pushButton can trigger a terminal command? f.ex netcat?
JonB last edited by
What is a "terminal command"? I see a Linux
netcatprogram. Does it keep running after you start it? Does it write stdout?
I assume you mean you want to use
QProcessto run a command. The detail of having that invoked when a
QPushButtonis clicked is neither here nor there. You have to decide where you want its output to show, e.g. in an
xtermor read in & displayed by your calling program, etc.
Well, I am thinking of a scenario where i click a button an then a netcat command is executed in the linux terminal
JonB last edited by
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
QProcesscommand-line. Is that what you want?
@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.
@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?
QString program = "sh"; QStringList arguments; arguments << "-c" << "echo" << "'3b00010000001b010001000000120000013000002713000300030101'" << "|" << "xxd" << "-r" << "-p" << "|" << "nc" << "172.16.4.44 30013"; QProcess myProcess; myProcess.start(program, arguments);
JonB last edited by JonB
Although I admit I have not tried it, this does not look right. The syntax of
/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"