Python Script skips process of Shell Scipt file

  linux, python, shell

I’m trying to automate the deletion of a program with python and shell scripts.
this is the code i use to execute my shell scripts.

import subprocess

self.shellscript = subprocess.Popen([self.shellScriptPath], shell=True, stdin=subprocess.PIPE )
self.shellscript.stdin.write('yesn'.encode("utf-8"))
self.shellscript.stdin.close()
self.returncode = self.shellscript.wait()

This is the shell script that I want to run.

echo *MY PASSWORT* | sudo -S apt-get --purge remove *PROGRAM*
echo *MY PASSWORT* | sudo -S apt-get autoremove
echo *MY PASSWORT* | sudo -S apt-get clean

I know its not secure to code my passwort into it like this but I fix this later.

My Problem is that the commandline asks me to type y/n but the program skips that and nothing happends.

Source: Python Questions

LEAVE A COMMENT