How do a make a python script take input that has been piped to it. Is that a sys.argv
moment. To be clear I want to figure out how to code the python side to receive input like this:
cat someFile | domeSomething.py
Can this be done? Again, to clarify, I'm not wanting to write this as passing a filename to my script and then using open(filename)
I want to get piped input. Thanks for the help.
To get piped input, you need to read from stdin
:
import sys
print sys.stdin.read()
stdin
is a file, so feel free to use any of the methods of a file object .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.