Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to understand how piping works and am stuck at this point.

A log file is being streamed and its output is being piped to pigz. What I am trying to do is, redirect the pigz content to a python script as stdin.

I can't figure out how to redirect the data to script

This currently works:

./customread file_name | pigz -dc

This shows the log contents to stdout, how do I pipe it to the script from here?

I've tried

python script.py < `./customread file_name | pigz -dc`

I want to redirect the data as it comes in..

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Not being too familiar with what you're trying to get to, but I think you can just use another nested pipe. I've done similar in bash and zsh. With pigz outputting to stdout with -c, just pipe that to your python script looking for stdin.

./customread file_name | pigz -dc | python script.py

Have you tried something like above? It worked for me when I tried with;

tail -f /var/log/syslog | grep `hostname` | python test.py

Here's the Python I used courtesy of this post from Stackoverflow:

#!/usr/bin/python                                                   
import sys 
import os

while True:
    line = sys.stdin.readline()
    if not line:
        break
    sys.stdout.write(line) # or print, doesn't matter.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.