简体   繁体   English

Python 脚本在执行子进程行后结束

[英]Python script ends after executing subprocess line

After the subprocess command is executed, the cmd window asks for the enter key to be pressed.子进程命令执行后,cmd window 要求按下回车键。 I would like the python script to continue and automatically press enter.我希望 python 脚本继续并自动按 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 kali@xx.xxx.xxx.xx", shell=True)

Keyboard.press(Key.Return)

Keyboard.release(Key.Return)

I have found a work-around where I can pass commands at the end of the plink command.我找到了一种解决方法,我可以在 plink 命令的末尾传递命令。 Pexpect does not work with Windows and I had endless dramas with the windows version. Pexpect 不适用于 Windows 并且我在 windows 版本上玩得不亦乐乎。 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).从下面的代码可以看出,最终的程序是打开 VNC 查看器,自动建立与我的 AWS EC2 实例的连接并确保环境仍然适合我的需要(因为实例有时需要重新初始化tightvnc)。

import subprocess

subprocess.call('C:/Users/joshs/OneDrive/Documents/VNCViewer')
subprocess.call("plink -i /Users/joshs/OneDrive/Documents/Downloads/newkey.ppk kali@xx.xxx.xxx.xx 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 kali@xx.xxx.xxx.xx")
subprocess.call(['C:\Program Files\RealVNC\VNC Viewer'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM