hi.
i was wondering, what's the simplest way to echo the standard input to
the standard output, with no modification.
i came up with:
....
while True:
try:
raw_input()
except EOFError:
break
....
but i guess there must be a simpler way.
using bash i simply do 'cat', *sigh*!
bye
max
ps: in perl you ca do this:
....
while ($line = <STDIN>)
{
print STDOUT ("$line");
}
.... 8 2381
2005/8/19, max(01)* <ma**@fisso.cas a>: hi. i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification. i came up with: ... while True: try: raw_input() except EOFError: break ... but i guess there must be a simpler way. using bash i simply do 'cat', *sigh*! bye max ps: in perl you ca do this: ... while ($line = <STDIN>) { print STDOUT ("$line"); } ...
Try this.
import sys
line = sys.stdin.readl ine()
while line:
sys.stdout.writ e(line)
line = sys.stdin.readl ine()
--
I like python!
My Donews Blog: http://www.donews.net/limodou
On Fri, 19 Aug 2005 15:26:27 GMT,
"max(01)*" <ma**@fisso.cas a> wrote: ps: in perl you ca do this:
... while ($line = <STDIN>) { print STDOUT ("$line"); } ...
import fileinput
import sys
for line in fileinput.input ():
sys.stdout.writ e(line)
Regards,
Dan
--
Dan Sommers
<http://www.tombstoneze ro.net/dan/>
import sys
for l in sys.stdin:
sys.stdout.writ e(l)
-- George
max(01)* wrote: i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification.
import sys
for line in iter(sys.stdin. readline, ''):
sys.stdout.writ e(line)
Note that this uses the second form of iter(), which calls its first
argument repeatedly until it returns the sentinel value (its second
argument).
STeVe gr*@ll.mit.edu wrote: import sys for l in sys.stdin: sys.stdout.writ e(l)
This is fine if you don't need the reads and writes of lines to run in
lockstep. File iterators read into a buffer, so you'll probably read
4096 bytes from stdin before you ever write a line to stdout. If that's
okay, this is a good solution. OTOH, if you want the reads and writes
to run in lockstep, you should probably use this idiom:
import sys
for line in iter(sys.stdin. readline, ''):
sys.stdout.writ e(line)
STeVe
P.S. You may also be able to get your version working using the -u
(unbuffered) option to Python, but I couldn't.
limodou wrote: 2005/8/19, max(01)* <ma**@fisso.cas a>:
hi.
i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification.
i came up with:
... while True: try: raw_input() except EOFError: break ...
but i guess there must be a simpler way.
using bash i simply do 'cat', *sigh*!
bye
max
ps: in perl you ca do this:
... while ($line = <STDIN>) { print STDOUT ("$line"); } ...
Try this.
import sys
line = sys.stdin.readl ine() while line: sys.stdout.writ e(line) line = sys.stdin.readl ine()
Try this:
import sys
for line in sys.stdin:
sys.stdout.writ e(line)
On Fri, 19 Aug 2005 15:26:27 GMT, max(01)* <ma**@fisso.cas a> wrote: hi.
i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification.
i came up with:
.... but i guess there must be a simpler way.
using bash i simply do 'cat', *sigh*!
.... ps: in perl you ca do this:
... while ($line = <STDIN>) { print STDOUT ("$line"); } ...
Actually, in perl it's easier than that, if you can tolerate that it also
filters file(s) given on the command-line:
while(<>) {
print;
}
or even:
#!/usr/bin/perl -p
;
Of course, not every programming language needs to have easy-to-use
filtering capabilities at the core.
/Jorgen
--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
max(01)* wrote: i was wondering, what's the simplest way to echo the standard input to the standard output, with no modification.
.... ps: in perl you ca do this:
... while ($line = <STDIN>) { print STDOUT ("$line"); } ...
I guess you could, but there wouldn't be much point. In Perl, you can
do this with just command-line flags:
perl -pe '' input.txt
Or if you really want something to put in a file:
print <>
Here's the closest thing I could come up with in Python:
import sys
for line in sys.stdin:
print line, This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dan Stromberg |
last post by:
Is there a way of setting O_DIRECT on a preexisting file like sys.stdin?
Does C allow this sort of thing?
Thanks!
|
by: Jonathan Neill |
last post by:
I'm aware that there is no ANSI (or POSIX, or any standard, to my knowledge)
way of flushing stdin or any other application-level input buffer, but if
anyone knows a hack or a non-portable way to do this, no matter how obscure
or arcane, I'd appreciate it.
|
by: herrcho |
last post by:
What's the difference between STDIN and Keyboard buffer ?
when i get char through scanf, i type in some characters and press
enter,
then, where do the characters go ? to STDIN or Keyboard buffer ? are
they same ?
thanks ^^
|
by: Charlie Zender |
last post by:
Hi,
I have a program which takes the output filename argument from stdin.
Once the program knows the output filename, it tries to open it.
If the output file exists, the program asks the user to confirm
whether he really wants to overwrite the existing output file.
The problem is that the second read from stdin, to obtain the user
response whether to overwrite the existing output file, never
waits for the user's response. It's as if a...
|
by: ccdrbrg |
last post by:
What is the best way to protect stdin within a library?
I am writing a terminal based program that provides plugin
capability using the dlopen() API.
Sequencing program commands (typed) and library input
prompts will not happen if stdin is supplied by pipe
or redirection.
So, I would like to include a statement in the pluggin
| |
by: orium69 |
last post by:
Hi!
how could i know if it was written something in stdin since the last
time i read it?
Tks...
|
by: aine_canby |
last post by:
The following line in my code is failing because sys.stdin.encoding is
Null. This has only started happening since I started working with
Pydef in Eclipse SDK. Any ideas?
uni=unicode(word,sys.stdin.encoding)
Thanks,
Aine.
|
by: Nikos Chantziaras |
last post by:
Hello.
Is there a way to check if the current process has an stdin handle? In
the win32 API, one can do:
_eof(_fileno(stdin))
Crucial here is that the above doesn't block. Is there a standard way
to do the same without resorting to OS-specific API calls?
|
by: Jean-Paul Calderone |
last post by:
On Sat, 21 Jun 2008 12:35:02 -0700 (PDT), joamag <joamag@gmail.comwrote:
Twisted supports asynchronous handling of stdin on both POSIX and Windows.
See stdiodemo.py and stdin.py under the Miscellaenous section at
http://twistedmatrix.com/projects/core/documentation/examples/
Jean-Paul
|
by: fbertasso |
last post by:
Hi,
I´m opening stdin to get a file and pass it through a pipe.
razor=popen ("/var/qmail/bin/razor-check -home=/var/qmail/razor",
"w");
while( (ret=fread(linha,1,sizeof(linha),stdin) ) 0 ) {
fwrite(linha,1,sizeof(linha),razor);
}
pclose(razor)
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |