16

I would like to do something like this:

find -name "foo*" | python main.py

and access all the files that were found by the find program. How do I access that in Python?

1
  • What about command which ran for a long time, e.g top.
    – SuB
    Oct 18, 2015 at 8:55

5 Answers 5

21
import sys
for line in sys.stdin:
    print line
4

Use sys.stdin.read() or raw_input()

A pipeline just changes the stdin file descriptor to point to the pipeline that the command on the left is writing to.

4

I Like using $(...) for command-line arguments that are dependent on some other program. I think this would work for your program python main.py $(find -name "foo*"). Found here

2

I think you can do:

import sys
print sys.stdin.readlines() #or what you want
1

I believe fileinput may be what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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