当命令提示时自动按键按回车键

2024-09-20 17:33:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在命令提示符下执行命令后自动按enter键,例如,我运行。。。。在

    d:\myunit> codecov instrument -ip

它输出:

Warning: It is recommended when instrumenting code that you use the sub-unit option for 'codecov' to avoid instrumentation being inserted in the source code in your development unit. Press 'enter' to continue with-out using a sub-unit.

如果该命令实际上是从python脚本执行的(使用操作系统('codecov instrument-ip'))。如何使同一个脚本也按enter键以便脚本可以继续而不需要用户输入? 目前,我一直在尝试使用一个子流程,但不确定这是否是最好的解决方法,但还没有让它发挥作用。在


Tags: thetoinip脚本codecovcodeunit
1条回答
网友
1楼 · 发布于 2024-09-20 17:33:34
from subprocess import Popen, PIPE
import os, sys, subproces

read, write = os.pipe() 
os.write(write, b"\n")
os.close(write)
subprocess.check_call('codecov instrument -ip', stdin=read, shell=True)

这就是我能用的解决方案。在

相关问题 更多 >

    热门问题