I have an sql.exe
which has a command line interface, takes as input an sql query and prints the results. I need to write a program in Python, which will generate the sql commands, pass them as input to this program and read the output.
For exercise, I have written a toy program in python, adder.py
:
if __name__ == '__main__':
while True:
try:
line = input()
a, b = line.strip().split()
c = int(a) + int(b)
print(c)
except EOFError:
exit()
except:
continue
I have created a in.txt
file:
10 5
7 3
1 a
2 1
I execute from cmd: -$ python adder.py < in.txt > out.txt
and the out.txt is:
15
10
3
My question is, how can I stream / buffer the input and the output, to constantly communicate with the program, and not have to create and read from files again and again ?