473,382 Members | 1,658 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,382 software developers and data experts.

pipe command to script

How can I read input from stdin pipe from somewhere?

ex:
# echo hello | script.py

I was thinking opening file() or popen() with sys.stdin, but that
didn't work. I've done this before but don't have the code anymore and
can't figure it out again.

Thanks.

-Josh
Jul 18 '05 #1
2 1251
Josh Close wrote:
How can I read input from stdin pipe from somewhere?

ex:
# echo hello | script.py

I was thinking opening file() or popen() with sys.stdin, but that
didn't work. I've done this before but don't have the code anymore and
can't figure it out again.
sys.stdin is already an open file object. Just call sys.stdin.read().
Thanks.

-Josh


--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Jul 18 '05 #2
Nice, that's easy. I did it some other way last time that worked
also..... probably doing things twice the other way though.

Thanks!

-Josh
On Mon, 20 Sep 2004 12:24:25 -0700, Robert Kern <rk***@ucsd.edu> wrote:


Josh Close wrote:
How can I read input from stdin pipe from somewhere?

ex:
# echo hello | script.py

I was thinking opening file() or popen() with sys.stdin, but that
didn't work. I've done this before but don't have the code anymore and
can't figure it out again.


sys.stdin is already an open file object. Just call sys.stdin.read().
Thanks.

-Josh


--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #3

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

Similar topics

4
by: Rajarshi Guha | last post by:
Hi, I'm having a little trouble when I read from a named pipe. I create a pipe by os.mkfifo('/tmp/mypipe') and then open it for reading with fin = open('/tmp/mypipe','r+')
1
by: Ruben | last post by:
I am reading a large text file a chunk at a time using the readlines(buffer_size) statement. I get an IOERROR ERRNO 32 Broken Pipe command when I "pipe" the output to MYSQL database using the...
1
by: momena | last post by:
Hi experts, I need to write a perl script that will be called from a series of executables chained thru pipes that read from STDIN and writes to STDOUT. The following code works fine under regular...
2
by: Hoegje | last post by:
I am writing a C++ program, which should create a sub- process to start a telnet session to another server. Then it should login to that server (on the telnet login) and execute one or more...
7
by: Greg | last post by:
I am trying to implement the UNIX pipe command using C but with the "->" operator. Everything works fine with 1 pipe, but when I try to use 2 or more, it hangs up when reading the pipe_in...
2
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the...
17
by: David T. Ashley | last post by:
Hi, On a Linux platform, I have the need to call a compiled 'C' program from a PHP script (to do some special authentication), and to keep the information passed from the PHP script to the...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
2
by: Dhika Cikul | last post by:
Hello, I'm new in Python, i don't know my subject is correct or wrong. I have problem with my script. I want to change password with passwd password in python without user submitted anything...
6
by: lawrence k | last post by:
Suppose I have a PHP script that I call at the Linux command line (Ubuntu), and it gets all the paths to files and directories that exist inside of some directory. All this data gets stored in an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.