I have the problem that I want to start a program in bash with a python script and then give input to that program. Right now it looks like this:
string="somestringthatstartsprogram"
os.system(string)
and then the program waits for input, so I need something like this:
os.system(string, <<< "0")
the input is always 0. <<< works in a bash script but I don't know how to do that in python. Searching for this problem gives a lot of answers for the other way round, using input from bash to python, but that's not what I want.
I would be very glad if you could give me a hint how to solve that :)
kind regards, bwp
Edit: Thank you very much for that useful hint. I've just started with python and don't now what I did exactly but it worked. Here is the solution:
#import subprocess
#import shlex
string="somestringthatstartsprogram"
args = shlex.split(string)
p = subprocess.Popen(args,stdout=subprocess.PIPE, stdin=subprocess.PIPE,stderr=subprocess.PIPE)
stdout_data = p.communicate(input='0')[0]