I'm trying to send .txt input to a python script using subprocess.Popen. My problem is python_anywhere keeps trying to run the input stdin as python.
I tried the exact same code on replit.com and it worked. What's going on?
Here is my code:
myinput = open('work/input_file.txt') # input file -NOT python
myoutput = open('work/results.txt') # output file
p = subprocess.Popen(['python', 'work/testFile.py'], stdin=myinput, stdout=myoutput, text=True)
Stored in testFile.py is a simple script:
a = input().split()
print(a)
Stored in input_file.txt is a simple text:
a b c d e f g
I get the following error:
Traceback (most recent call last):
File "work/testFile.py", line 1, in <module>
a = input().split()
File "<string>", line 1
a b c d e f g
^
SyntaxError: invalid syntax