How to add a button that runs a command line in Raspbian terminal ?
-
wrote on 18 Aug 2022, 06:58 last edited by
Hello,
i want to run this line in raspbian Terminal to activate PiCAN raspberry pi module:pi@raspberrypi:~ $ sudo /sbin/ip link set can0 up type can bitrate 1000000 loopback on
How can i do it ?
Qt5-12 -
Hello,
i want to run this line in raspbian Terminal to activate PiCAN raspberry pi module:pi@raspberrypi:~ $ sudo /sbin/ip link set can0 up type can bitrate 1000000 loopback on
How can i do it ?
Qt5-12 -
wrote on 18 Aug 2022, 08:14 last edited by
I've tried this code but he didn't found the command:
from(https://forum.qt.io/topic/113592/run-command-line-from-qt-app-in-linux/6)
void ConnectDialog::on_Connect_Button_clicked()
{
using namespace std;
qDebug()<<"checking the use of ls in qt * \n";
QProcess process;
process.setWorkingDirectory("/home/pi");QString Command; //Contains the command to be executed QStringList args; //Contains arguments of the command Command = "sudo"; args<<"/sbin/ip link set can0 up type can bitrate 1000000 loopback on"<<"/home/pi"; qDebug()<<"Home cmd"<<Command; qDebug()<<"Home args"<<args; process.start(Command, args, QIODevice::ReadOnly); //Starts execution of command process.waitForFinished(); QString StdOut = process.readAllStandardOutput(); //Reads standard output qDebug()<<"\n Printing the standard output..........\n"; // invalid // qDebug()<<StdOut; //cout<<"\n Printing the standard error..........\n"; QString StdError = process.readAllStandardError(); //Reads standard error qDebug()<<StdError;
}
-
I've tried this code but he didn't found the command:
from(https://forum.qt.io/topic/113592/run-command-line-from-qt-app-in-linux/6)
void ConnectDialog::on_Connect_Button_clicked()
{
using namespace std;
qDebug()<<"checking the use of ls in qt * \n";
QProcess process;
process.setWorkingDirectory("/home/pi");QString Command; //Contains the command to be executed QStringList args; //Contains arguments of the command Command = "sudo"; args<<"/sbin/ip link set can0 up type can bitrate 1000000 loopback on"<<"/home/pi"; qDebug()<<"Home cmd"<<Command; qDebug()<<"Home args"<<args; process.start(Command, args, QIODevice::ReadOnly); //Starts execution of command process.waitForFinished(); QString StdOut = process.readAllStandardOutput(); //Reads standard output qDebug()<<"\n Printing the standard output..........\n"; // invalid // qDebug()<<StdOut; //cout<<"\n Printing the standard error..........\n"; QString StdError = process.readAllStandardError(); //Reads standard error qDebug()<<StdError;
}
wrote on 18 Aug 2022, 08:18 last edited by@imene said in How to add a button that runs a command line in Raspbian terminal ?:
args<<"/sbin/ip link set can0 up type can bitrate 1000000 loopback on"<<"/home/pi";
This is quite wrong. In no way is
/sbin/ip link set can0 up type can bitrate 1000000 loopback on
a single argument!Either
- Every one of those space-separated words is a separate argument, like
args << "/sbin/ip" << "link" << "set" << ....
; or - Use
/bin/sh
as the command andargs << "-c" << "sudo /sbin/ip link set can0 up type can bitrate 1000000 loopback on"
.
- Every one of those space-separated words is a separate argument, like
1/5