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 connectivity
givesfull
echo 'pwdthatshouldbeavoidedIknow' | sudo -S -n systemctl restart rtunnel.service
works when executed as the same user that executes the program in a terminal.- Other
sudo
commands work too in the same program e.g.
Best Answer:
You can not use Pipes inQProcess.start()
. After some testing I found out that sudo
doesn’t work as expected when not called from a command line interpreter.Start a
bash
and 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!
Source: Stackoverflow.com