Reputation: 21
I am trying to automatically press enter after I execute a command in command prompt, for example, I run....
d:\myunit> codecov instrument -ip
And it outputs:
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.
If that command is actually executed from a python script(using os.system('codecov instrument -ip')). How can I make the same script also press enter so that the script can continue without user input? Currently I have been trying to use a subprocess but am not sure if it is the best way to go about it and have not gotten it to work.
Upvotes: 1
Views: 1491
Reputation: 21
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)
This is what I was able to use as the solution.
Upvotes: 1