1

I am writing python script to uninstall openjdk.

uninstall_java1=["sudo" ,"apt-get" ,"remove" ,"openjdk*","y"]
subprocess.Popen(uninstall_java1)

This code is exiting at line:

Do you want to continue? [Y/n] Abort.

How can I pass "y" to this script as it is aborting automatically? Thanks.

sshashank124
  • 31,495
  • 9
  • 67
  • 76

1 Answers1

2

For your specific case, you can supply the -y/--yes flag to apt-get to automatically answer yes to all its questions:

uninstall_java1 = ["sudo", "apt-get", "remove", "-y", "openjdk*"]

For the more general case of communicating with a subprocess.Popen, check the question How do I pass a string into subprocess.Popen (using the stdin argument)? which recommends using Popen.communicate.

sshashank124
  • 31,495
  • 9
  • 67
  • 76