Python3 Tkinter - Write input (y) to console for subprocess
<p>I've been looking around for an answer to my problem but have been unlucky. I would like for the answer to work with native python and hopefully be simple.</p>

<p>My problem is that I'm using subprocess in my tkinter application, but one of the commands require you to write Y/N to be sure you want to proceed with the action.</p>

<p>So I'm looking for a way to write y into the terminal when a message like this appears:
Are you sure you want to continue? (y/N)</p>

<p>I've tried by running subprocess.run("y") but that doesn't seem to work.</p>

<p>I'm testing this on Debian Linux and to call the command that asks if I want to proceed, is subprocess.getoutput() so that I can check for errors.</p>

<p><strong><em>CODE</em></strong></p>

<pre><code>class RemovePublicKeyDialog:
def __init__(self, parent):
    top = self.top = Toplevel(parent)

    Label(top, text="Who to remove?").pack()

    self.e = Entry(top)
    self.e.pack(padx=5)

    b = Button(top, text="REMOVE", command=self.ok)
    b.pack(pady=5)

def ok(self):
    #print("value is " + self.e.get())
    key = self.e.get()
    cmd = subprocess.getoutput("gpg --delete-keys " + key)
    print(cmd)
    if ("key \"" + key + "\" not found" in cmd):
        messagebox.showerror("Error", "No such public key.")
    elif ("Delete this key from keyring?" in cmd):
        #subprocess.run("echo 'y'")
        messagebox.showinfo("Success", "Public key \"" + key + "\" deleted from keyring.")
    else:
        messagebox.showerror("Error", "Unknown error, did you input a key?")

    self.top.destroy()
</code></pre>

<p>This is the "main" code, everything works but it's just that I need to input Y to get it to proceed.</p>