here document as script and read from stdin
Eddie Corns
eddie at holyrood.ed.ac.uk
Wed Apr 21 07:33:09 EDT 2004
Robin Becker <robin at SPAMREMOVEjessikat.fsnet.co.uk> writes:
>Is it possible to use python with a shell HERE document as the script
>and read the standard input? In other words make python usable as a
>filter with a side input?
>It doesn't seem to be obvous unless I can somehow use the -c option.
>--
>Robin Becker
python -c "`cat <<OOK
from sys import stdin
for line in stdin:
print line.upper(),
print 'ha ha', "ho ho"
OOK
`"
ie the value of -c can be a complete program as long as you keep the newlines
intact and don't mess up the quotes. However it would probably be a lot
simpler to copy the script to a temp file and execute that (ignoring
pathological security issues).
(Only tested with bash!)
Eddie
More information about the Python-list
mailing list