In this post, we will see how to resolve System command executed from QT does not work for service
Question:Why does the service not get restarted?
- For an innocent command, things work well.
nmcli networking connectivitygives
echo 'pwdthatshouldbeavoidedIknow' | sudo -S -n systemctl restart rtunnel.serviceworks when executed as the same user that executes the program in a terminal.
sudocommands work too in the same program e.g.
Best Answer:You can not use Pipes in
QProcess.start(). After some testing I found out that
sudodoesn’t work as expected when not called from a command line interpreter.
bashand write your commands to it. Remember to exit the bash! Note that the newline characters in the
write‘s are important!
Note: The -S parameter in sudo is used to read the password from standard input instead of from the terminal.
If you have better answer, please add a comment about this, thank you!