I wrote a program (myProg.py) that uses subprocess module to run other python programs through the run function. I noticed that arg in input(arg) statements in these other python programs are not being displayed to the console (stdout), while args in print(args) are displayed properly. This only happens when I run my program through console. This does not happen when I run my program through LiClipse.
Here is the simplest way to replicate this situation:
Using python 3.6.2, and windows 10
- create a python program containing the following two lines and save it as someProgram.py:
a = input("Enter anything")
print("a has: " + a)
- open cmd, type: python
- type: import subprocess
- type: subprocess.run(["python", "path..to..someProgram.py"], stderr=subprocess.PIPE)
- No ouptut so far but the interpreter is waiting on input... type something and hit Enter.
- You will see the output from the print statement.
If you remove , stderr=subprocess.PIPE you will see the correct outputs.
Now, save the code from steps 2 & 3 in another file, call it myProg.py in the same folder as someProgram.py. Run myProg.py from LiClipse. You will find that the myProg.py runs fine and produces the correct outputs.
My questions are:
- Why is this problem with subprocess.run happening
- How can I solve it
- Why would there be a difference between running code through commandline and through an IDE.