您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Shell上提示时如何使python脚本按'enter'

在Shell上提示时如何使python脚本按'enter'

您可以使用subprocess.Popensubprocess.communicate将输入发送到另一个程序。

例如,将“ enter”键发送到以下程序test_enter.py

print "press enter..."
raw_input()
print "yay!"

您可以执行以下操作:

from subprocess import Popen, PIPE
p = Popen(['python test_enter.py'], stdin=PIPE, shell=True)
p.communicate(input='\n')

您可能还会发现“如何编写python子进程的stdin”的答案也很有帮助。

python 2022/1/1 18:23:05 有408人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶