Answer the question
In order to leave comments, you need to log in
How to run a python program using a bat file and enter data into it?
I have a python program with input and I need to run it through a bat file, and also enter data into this program through this file. Is that possible?
Answer the question
In order to leave comments, you need to log in
Of course available. I don’t have Windows at hand right now, but it will look something like this.
Program, let's call it my_python_script.py :
x = input()
print('Text from input:', x)
echo the string for python | python my_python_script.py
x = input()
y = input()
z = input()
rest = []
while z != 'END':
rest.append(z)
z = input()
print('x=', x, 'y=', y)
print('rest=', rest)
echo The X string
echo The Y string
echo Other string 1
echo line 2
echo line 3
echo line 4
echo END
my_script.bat | python.exe my_python_script.py
echo text to write into the file > the_file.txt
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question