Press Enter As Command Input
I have an installer of an application. It has .sh and .bat for *nix/windows os. In the scripts it will do something and hang there, waiting some other things to be done, then need
Solution 1:
One way is to use is to use the raw_input
method!
# Codeprint"Please press ENTER to continue!"
raw_input()
# more code
Solution 2:
You need to supply a newline on the installer's stdin.
One way:
subprocess.Popen('sh abc.sh < a_file_that_you_prepared.txt',
shell=True,
stdout=subprocess.PIPE)
Another, roughly equivalent to the first:
input_file = open('a_file_that_you_prepared.txt', 'r')
subprocess.Popen('sh abc.sh',
shell=True,
stdout=subprocess.PIPE,
stdin=input_file)
input_file.close()
Another way -- might work, might not:
subprocess.Popen('sh abc.sh < /dev/null',
shell=True,
stdout=subprocess.PIPE)
Third way -- can easily cause deadlock between your program and installer:
x = subprocess.Popen('sh abc.sh',
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
...
x.stdin.write('\n')
Post a Comment for "Press Enter As Command Input"