473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

here document as script and read from stdin

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
Jul 18 '05 #1
3 2712
Robin Becker wrote:
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.

Well I find I can put the script in as the -c option and then stdin is
still available. That requires me to be pretty careful with quotes
though. I wonder if there's an easy way to get a here document to act as
a parameter?
--
Robin Becker
Jul 18 '05 #2
In article <40************@jessikat.fsnet.co.uk>,
Robin Becker <ro***@SPAMREMOVEjessikat.fsnet.co.uk> wrote:
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.


Use "-" as the name of the file - e.g.,

python - << 'EOT'
import sys
print sys.argv
EOT

Donn Cave, do**@u.washington.edu
Jul 18 '05 #3
Robin Becker <ro***@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
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nader Emami | last post by:
L.S., Would somebody help me how i can write the 'here document' in Python script please? I have a csh script in which a program is invoked with some argument in the form of here document: ...
0
by: Joe Burnett | last post by:
Hello, I am using the following perl read function to read form information from a client web page: read(STDIN, $GN_QUERY, 100); Everything works fine on a Linux/Apache server. I get the...
7
by: Praxis Happenstance | last post by:
Check me out: http://www.c-sharpcorner.com/Code/2004/July/MultithreadedXmlDoc.asp Multithreaded XML Document for Read/Write Access by John Bailo
3
by: eight02645999 | last post by:
hi I need to execute sql command using a "here document" like in unix. os.popen("osql", "w").write("""\ select * from table go """) how can i pipe these result of the select into a...
3
by: ifmusic | last post by:
Hi!, i have a "server-like" application: i use select to accept and recieve data from Sockets. I want to Add a menu to this app something like "pick an option" thing, but it has to show data...
2
by: Brendan Fay | last post by:
Dear Someone: I have written a script that accesses the googleAPI through pygoogle and saves each of the ten documents as a .txt file by using a specific function for each respective file type...
1
by: monomaniac21 | last post by:
Hi on one of my computers the here document syntax (<<<END END;) is not working however when used on other comps it is fine. What setting needs changing here? regards marc
4
by: Adam Funk | last post by:
I'm using this sort of standard thing: for line in fileinput.input(): do_stuff(line) and wondering whether it reads until it hits an EOF and then passes lines (one at a time) into the...
1
by: Mufasa | last post by:
I have a need to have a program open a Word document and display it to the user. The user will not be able to touch the document - it will be read only. Anybody have any code or links that do...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.