I have the following program to test input redirection in Python.
a = int(raw_input("Enter a number: "))
b = raw_input("Enter a string: ")
print "number entered = ", a
print "string entered = ", b
If I run this program without redirection, the input and output are shown below:
Enter a number: 100
Enter a string: sample
number entered = 100
string entered = sample
Now, to test input redirection, I have a file a.txt named that contains:
100
sample
However, when I run with input redirected from a.txt (as below), my input and output gets garbled.
python doubt02.py < a.txt
Enter a number: Enter a string: number entered = 100
string entered = sample
Please suggest if I have a better alternative to see (with input redirection) as below:
Enter a number: 100
Enter a string: sample
number entered = 100
string entered = sample