I am python and I am trying to write a python script to which you can connect the output of a command or script.
example command | python_sript.py
In a python script, I will mainly analyze the output of the command and save it to a file.
I thought I could do this by redirecting sys.stdin to subprocess.PIPE, but that didn't work.
sys.stdin = subprocess.PIPE
Can anyone suggest how I should approach this?
Also, what happens if a command or script transmits data at a higher speed than what a python script can handle.
Note. When i use this script
import sys
data = sys.stdin.readline()
print(data)
I get it
D:\>echo "test" | tee.py
The process tried to write to a nonexistent pipe.
Traceback (most recent call last):
File "D:\Profiles\Administrator\My Documents\Workspace\tee.py", line 3, in <mo
dule>
data = sys.stdin.readline()
AttributeError: 'NoneType' object has no attribute 'readline'
and when i use this
import sys
data = input()
print(data)
I get it
D:\>echo "test" | tee.py
The process tried to write to a nonexistent pipe.
Traceback (most recent call last):
File "D:\Profiles\Administrator\My Documents\Workspace\tee.py", line 3, in <mo
dule>
data = input()
RuntimeError: input(): lost sys.stdin
source
share