Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > confused about stdin

Reply
Thread Tools

confused about stdin

 
 
David Bear
Guest
Posts: n/a
 
      10-21-2004
This may be a dumb question but I'm confused.

using command line syntax pipe like this:

cat somefile | pyscript

In my pyscript I can simply do

buffer = sys.stdin.read()

to get all of whatever cat sends.

However, using syntax like this:

pyscript < somefile

I'm not sure. Does this send to stdin as well?

And.. will it work on both unix and windows?

--
David Bear
phone: 480-965-8257
fax: 480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
"Beware the IP portfolio, everyone will be suspect of trespassing"
 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      10-22-2004
David Bear wrote:

> This may be a dumb question but I'm confused.
>
> using command line syntax pipe like this:
>
> cat somefile | pyscript
>
> In my pyscript I can simply do
>
> buffer = sys.stdin.read()
>
> to get all of whatever cat sends.
>

Correct. But this uses a "cat" process to very little effect.

> However, using syntax like this:
>
> pyscript < somefile
>
> I'm not sure. Does this send to stdin as well?
>

Yes. Now standard input is the content of the named file, where in the
first case it was the output of the preceding process in the pipe.

The pipe case is much more useful where you are actually transforming
information rather than just using it directly, such as

sort somefile | pyscript

Since "cat" doesn't do any transformation at all, using file redirection
as in your second example is generally better practice than your first
example.

> And.. will it work on both unix and windows?
>

Reasonably well, yes, though (at least) some Windows implementations
will use intermediate files rather than in-memory buffers to implement
the pipes, so you could end up getting less parallelism than you
anticipate.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peek at stdin, flush stdin Johnathan Doe C Programming 5 05-17-2013 04:30 PM
How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute() Ben C Programming 2 08-29-2009 09:47 PM
STDIN, OUT, ERR and $stdin, out, err - Differences? Terry Cooper Ruby 7 06-09-2009 05:48 AM
Reading from stdin then launching a program that reads from stdin strange behaviour Stefano Sabatini Perl Misc 6 07-29-2007 10:38 PM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments