I am trying to pipe output logs to another script for processing. However, if I undestand this issue correctly, powershell waits for first command to finish before sending output to second command.
For example, this works as expected (script receives "hi"), since echo
finishes quickly:
echo "hi" | python script.py
While in this one (caddy
is webserver, so it doesn't finish) caddy's stdout never reaches script's stdin:
caddy run | python script.py
Is it possible to forward output of first command to second asynchronously, without waiting for first to finish?
--
Edit: minimal example
# output.py
from time import sleep
while True:
print("SENDING")
sleep(1)
# onetime.py
print("SENDING")
# input.py
import sys
while True:
for line in sys.stdin:
print(f"Received: {line}")
This works (prints to stdout Received: SENDING
):
python onetime.py | python input.py
This doesn't work (nothing is printed):
python output.py | python input.py