Answer the question
In order to leave comments, you need to log in
How to use subprocess to pass the password from sudo but not make the process blocked?
Hello, tell me, is there such a tcpdump tool,
I need to run it at a certain moment so that it starts running and the logs are written to a file. the console output is not needed, but it requires sudo password
here is what I did:
import subprocess
import signal
command = ['sudo', '-S','tcpdump', '-w', '/home/user/dump.pcap']
output = subprocess.Popen(command, stdout=subprocess.PIPE, stderr = subprocess.STDOUT, encoding='utf8' )
out,data = output.communicate('password'+'\n')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question