'Python script ends after executing subprocess line

After the subprocess command is executed, the cmd window asks for the enter key to be pressed. I would like the python script to continue and automatically press enter. my current code is as follows:

import subprocess

import pynput

from pynput.keyboard import Key, Controller

Keyboard = Controller()

subprocess.call("plink -i /Users/joshs/OneDrive/Documents/Downloads/newkey.ppk [email protected]", shell=True)

Keyboard.press(Key.Return)

Keyboard.release(Key.Return)


Solution 1:[1]

I have found a work-around where I can pass commands at the end of the plink command. Pexpect does not work with Windows and I had endless dramas with the windows version. As you can tell from the code below, the final program is to open VNC viewer, automatically establish connection with my AWS EC2 instance and make sure the environment is still suitable for my needs (as the instance sometimes requires tightvnc to be reinitialised).

import subprocess

subprocess.call('C:/Users/joshs/OneDrive/Documents/VNCViewer')
subprocess.call("plink -i /Users/joshs/OneDrive/Documents/Downloads/newkey.ppk [email protected] sudo apt install xfce4 xfce4-goodies -y tightvncserver; sudo apt-get install gnome-core kali-defaults kali-root-login desktop-base -y ; tightvncserver -geometry 1920x1080; sudo gunzip /usr/share/wordlists/rockyou.txt.gz")
subprocess.call("plink -L 5901:localhost:5901 -N -i /Users/joshs/OneDrive/Documents/Downloads/newkey.ppk [email protected]")
subprocess.call(['C:\Program Files\RealVNC\VNC Viewer'])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tripleee