Replicating "terminal " command sequence
-
I can successfully complete the following while running “terminal “.
nov25-1@nov251-desktop:~$ sudo su
[sudo] password for nov25-1:
root@nov251-desktop:/home/nov25-1# ln -s -v /dev/ttyUSB0 /dev/rfcomm0My tasks to duplicate that sequence using C code.
Here is my basic C code to process “command “:
QP = new QProcess(); QP->start("/bin/sh", QStringList() << "-c" << command); if(QP->Running) if (QP->waitForReadyRead(60000)) QP->waitForFinished(100); ….. else { text = " ERROR waitForReadyRead(500) timed out "; }
I have no issues processing test command – such as “lsusb”.
However , here is my debug output when I use “sudo su”
Test option ...
BTUL->ProcessCommand_Raw elapsed time 39 mS
sudo: a terminal is required to read the password; either use the -S option to
read from standard input or configure an askpass helper
sudo: a password is requiredand this is what I receive after command “sudo -S”
Test option ...
BTUL->ProcessCommand_Raw elapsed time 29 mS
usage: sudo -h | -K | -k | -V
usage: sudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
[command]
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
[VAR=value] [-i|-s] [<command>]
usage: sudo -e [-ABknS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...That is telling me that “sudo -S” is invalid…
Please note
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
[VAR=value] [-i|-s] [<command>]is a valid usage option – or am I missing something ?
PS
I would also like to find out , later - after this is resolved, why my code always “times out” when invalid command is processed. -
I can successfully complete the following while running “terminal “.
nov25-1@nov251-desktop:~$ sudo su
[sudo] password for nov25-1:
root@nov251-desktop:/home/nov25-1# ln -s -v /dev/ttyUSB0 /dev/rfcomm0My tasks to duplicate that sequence using C code.
Here is my basic C code to process “command “:
QP = new QProcess(); QP->start("/bin/sh", QStringList() << "-c" << command); if(QP->Running) if (QP->waitForReadyRead(60000)) QP->waitForFinished(100); ….. else { text = " ERROR waitForReadyRead(500) timed out "; }
I have no issues processing test command – such as “lsusb”.
However , here is my debug output when I use “sudo su”
Test option ...
BTUL->ProcessCommand_Raw elapsed time 39 mS
sudo: a terminal is required to read the password; either use the -S option to
read from standard input or configure an askpass helper
sudo: a password is requiredand this is what I receive after command “sudo -S”
Test option ...
BTUL->ProcessCommand_Raw elapsed time 29 mS
usage: sudo -h | -K | -k | -V
usage: sudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
[command]
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
[VAR=value] [-i|-s] [<command>]
usage: sudo -e [-ABknS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...That is telling me that “sudo -S” is invalid…
Please note
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
[VAR=value] [-i|-s] [<command>]is a valid usage option – or am I missing something ?
PS
I would also like to find out , later - after this is resolved, why my code always “times out” when invalid command is processed.@AnneRanch said in Replicating "terminal " command sequence:
That is telling me that “sudo -S” is invalid…
Please note
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
[VAR=value] [-i|-s] [<command>]
is a valid usage option – or am I missing something ?Ann, hmmm... sudo is a Unix command
https://en.wikipedia.org/wiki/SudoFolks on Unix/Linux forums are the specialists I would ask this question to
Please visit https://unix.stackexchange.com/
-
@AnneRanch said in Replicating "terminal " command sequence:
That is telling me that “sudo -S” is invalid…
Please note
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
[VAR=value] [-i|-s] [<command>]
is a valid usage option – or am I missing something ?Ann, hmmm... sudo is a Unix command
https://en.wikipedia.org/wiki/SudoFolks on Unix/Linux forums are the specialists I would ask this question to
Please visit https://unix.stackexchange.com/
@Txai Go ahead and ask...I am banned to do so there ....
-
I can successfully complete the following while running “terminal “.
nov25-1@nov251-desktop:~$ sudo su
[sudo] password for nov25-1:
root@nov251-desktop:/home/nov25-1# ln -s -v /dev/ttyUSB0 /dev/rfcomm0My tasks to duplicate that sequence using C code.
Here is my basic C code to process “command “:
QP = new QProcess(); QP->start("/bin/sh", QStringList() << "-c" << command); if(QP->Running) if (QP->waitForReadyRead(60000)) QP->waitForFinished(100); ….. else { text = " ERROR waitForReadyRead(500) timed out "; }
I have no issues processing test command – such as “lsusb”.
However , here is my debug output when I use “sudo su”
Test option ...
BTUL->ProcessCommand_Raw elapsed time 39 mS
sudo: a terminal is required to read the password; either use the -S option to
read from standard input or configure an askpass helper
sudo: a password is requiredand this is what I receive after command “sudo -S”
Test option ...
BTUL->ProcessCommand_Raw elapsed time 29 mS
usage: sudo -h | -K | -k | -V
usage: sudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
[command]
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
[VAR=value] [-i|-s] [<command>]
usage: sudo -e [-ABknS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...That is telling me that “sudo -S” is invalid…
Please note
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group]
[-h host] [-p prompt] [-R directory] [-T timeout] [-u user]
[VAR=value] [-i|-s] [<command>]is a valid usage option – or am I missing something ?
PS
I would also like to find out , later - after this is resolved, why my code always “times out” when invalid command is processed.@AnneRanch said in Replicating "terminal " command sequence:
lsusb
You can not run sudo in qt since password is needed. It is better to do this kind of executions with (sudo + a script) before your app is launched. It is not a good design
to run sudo inside your qt app.If you have to, maybe create a service which has sudo privilege. Your Qt app can send a message to the service to run these operations.
-
@AR --
You are going to keep having problems with these embedded command line sequences. quoting/escaping embedded command sequences is a PITA, and can be mitigated by creating subshell scripts and just calling the script instead of trying to build a long convoluted command line on execution. It also has the benefit of allowing for easier testing because you can work out the script directly and not involve Qt until you are ready.