I am trying to run this command sudo nmap -sP -n
with python subprocess library, my goal is creating script when I run the command the script will read the password from a file and add it to the subprocess and execute the command. The problem is that I allways have to write password to execute the command.
I have tried this, but it did not work for me.
p = subprocess.Popen(["sudo", "nmap", "-sP", "-n", network], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write(bytes("Mypassword", "utf-8"))
I found some solutions here Use subprocess to send a password, I tried all of them but it did not work for me. Any idea how can I solve the problem?