Sending command to terminal
I am currently using Fedora 23 and QT 5.6. I am building a command for Hping3 and trying to send that command to the terminal and receive the results. I can get the terminal to open but I can not get it to receive any commands. I am very new to QT so my knowledge is minimal. I learned programming with Visual Basic so I understand logic but this syntax is killing me.
Code:
//Sending the command to terminal
proc.start("/usr/bin/gnome-terminal");
proc.waitForStarted();
proc.write("su");
proc.write("ite");
//proc.write(command);
proc.waitForFinished();
proc.close();
ui->dgvResults->setText(output);
I am trying to display in a QTextBrowser and Commented out that one write command because I am getting an error
/home/itestudent/SeniorProject/frmmain.cpp:112: error: no matching function for call to 'QProcess::write(QString&)'
proc.write(command);
^
Command is declared at the top of the button push event
QString command = "hping3 -S ";
Re: Sending command to terminal
Why do you need the terminal?
Why not just execute the command?
Cheers,
_
Re: Sending command to terminal
I get an error when I try to execute with out starting a process so I was using terminal in hopes of seeing the commands working somewhere. The error is QIODevice::read (QProcess): device not open. So what I think I really want to do is start bash and I tried running it in execute and it seems like it is running, at least it waits a few seconds like it is processing before it continues, but I can not fill the display with the results of the command or be certain this is working. If I alter the display command ui->dgvResults->setText(output); to "test" it displays.
Code:
proc.start("/bin/bash");
proc.waitForStarted();
proc.execute(command);
proc.waitForFinished();
ui->dgvResults->setText(output);
proc.close();
Added after 27 minutes:
I just want to let everyone know that i solved this with this line of code
QProcess proc;
proc.start("/bin/bash", QStringList() << "-c" << command);
proc.waitForFinished();
QByteArray output = proc.readAll();
proc.close();
ui->dgvResults->setText(output);
Re: Sending command to terminal
You could also just run the command itself, no need to go through a terminal or bash.
Cheers,
_