I want to create a graphical python application that can execute some external programs on Linux without showing the terminal.
First, I tried to use subprocess.run() to see if it actually works, but Python 3.7.3 shows no results to the code I wrote.
import subprocess
subprocess.run(['sudo', 'apt', 'update'])
I changed it to see any results:
import subprocess
a = subprocess.run(['sudo', 'apt', 'update'])
print(a)
but it shows this result instantly:
CompletedProcess(args=['sudo', 'apt', 'update'], returncode=1)
This script will take at least 5 seconds to be finished, and it requires sudo privileges to be able to run it in the first place, so I don't think that Python shell executed this script.
Exit status of the child process. Typically, an exit status of 0 indicates that it ran successfully./etc/sudoersfile. By default, applications without a TTY aren't allowed to use sudo at all. Maybe usegksudo, which is explicitly intended for graphical use, instead?subprocess.run([...], stdout=subprocess.PIPE, stderr=subprocess.PIPE). see this answer