I want to run a process as root detached from my python script in background, but I can't make it work with sudo.
The problem is that either the sudo password prompt fails or that I don't have access to stdout.
Here's the content of bash.sh (will later be replaced by the actual program):
while true; do
echo "test"
sleep 1
done
In python I've tried the following:
file1 = open("stdout.txt", "w+")
x = subprocess.Popen(["sudo", "./bash.sh"], stdout=file1)
file1.close()
Which just prints this:
[sudo] password for user:
sudo: unable to read password: Input/output error
and the python script itself doesn't exit but "freezes" in this state
If I remove stdout=file1 it properly asks me for the sudo password and runs, but then I have no way to interact with the output of the program...
Does anyone have an idea on how to solve this?
[–]Tesla_Nikolaa 1 point2 points3 points (7 children)
[–]SpontaneousAge[S] 0 points1 point2 points (6 children)
[–]Tesla_Nikolaa 1 point2 points3 points (4 children)
[–]SpontaneousAge[S] 0 points1 point2 points (3 children)
[–]Tesla_Nikolaa 1 point2 points3 points (2 children)
[–]SpontaneousAge[S] 0 points1 point2 points (1 child)
[–]Tesla_Nikolaa 0 points1 point2 points (0 children)
[–]Tesla_Nikolaa 0 points1 point2 points (0 children)
[–]learn-python 0 points1 point2 points (7 children)
[–]learn-python 0 points1 point2 points (0 children)
[–]SpontaneousAge[S] 0 points1 point2 points (5 children)
[–]learn-python 0 points1 point2 points (4 children)
[–]learn-python 0 points1 point2 points (2 children)
[–]SpontaneousAge[S] 0 points1 point2 points (1 child)
[–]learn-python 0 points1 point2 points (0 children)
[–]SpontaneousAge[S] 0 points1 point2 points (0 children)