Hello Everyone,
I have managed to execute bash scripts to log in to my raspberry using QDesktopServices:
void Project::on_sshlogin_clicked()
{
QString loginfilename
= "./path/to/script";
// path to login script }
void Project::on_sshlogin_clicked()
{
QString loginfilename= "./path/to/script"; // path to login script
QDesktopServices::openUrl(QUrl("file:///"+loginfilename,QUrl::TolerantMode));
}
To copy to clipboard, switch view to plain text mode
This opens a terminal and executes the bash script, which logs into the RPi using 'expect' and can then administer commands.
I do not want to have a terminal window open. So I decided to use QProcess to run the script in the background:
void Project::on_sshlogout_clicked()
{
QString MainDirectory
= "/path/to/script/directory";
logout->setWorkingDirectory(MainDirectory);
logout
->start
("/usr/bin/expect",
QStringList() <<
"<nameofscript>.sh");
}
void Project::on_sshlogout_clicked()
{
QProcess *logout = new QProcess();
QString MainDirectory = "/path/to/script/directory";
logout->setWorkingDirectory(MainDirectory);
logout->start("/usr/bin/expect", QStringList() << "<nameofscript>.sh");
}
To copy to clipboard, switch view to plain text mode
I verify that this runs because I kill all active ssh sessions in the script.
So, I login and a terminal opens up and I can use the ssh terminal in the window. I click the logout button on my GUI and the Qprocess runs a similar script in the background and the initial ssh session is exited.
OK!!! So, I would like to make all both login and logout QProcesses as well, and have other buttons to perform commands.
First problem! I cannot get a reading of the output from the QProcess I have been trying to implement:
controlon
->setProcessChannelMode
(QProcess::ForwardedChannels);
controlon->setProcessChannelMode(QProcess::ForwardedChannels);
To copy to clipboard, switch view to plain text mode
However, I cannot get this to work. I would like to print the command entered, then the output of a normal command (such as ls,cd etc.). Just so I understand the basics.
Which brings me to my second problem! After I manage to do this I would like to monitor the output every second from a command that runs until exited. I will then extract values that I can use to control value displays on my GUI.
These values will be set by sending another command while the process is running.
Thank you for your help
I will post any finished solution because I believe that this is more useful than random lines of code which is all I can find.
I will seek a more elegant solution using libssh at a later date and provide this solution also, any tips for setting up a basic test with libssh for raspberry pi connection would be greatly appreciated!
Ciao!
Bookmarks