Python论坛  - 讨论区

标题:[python-chinese] 如何读取输入流

2006年08月03日 星期四 11:15

曹翔 caoxiang at tomonline-inc.com
Thu Aug 3 11:15:22 HKT 2006

如何在linux下读取管道进来的数据呢?

 

比如 ls | a.py 这样。

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060803/7b8903cf/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月03日 星期四 11:19

IQDoctor huanghao.c at gmail.com
Thu Aug 3 11:19:27 HKT 2006

pipe()?
也许你想 os.popen(x, ["r"]["w"]) ?

在 06-8-3,曹翔<caoxiang at tomonline-inc.com> 写道:
>
>
>
> 如何在linux下读取管道进来的数据呢?
>
>
>
> 比如 ls | a.py 这样。
>
>
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request at lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
Best regrads,
IQDoctor

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月03日 星期四 13:49

Leira Hua lhua at altigen.com.cn
Thu Aug 3 13:49:32 HKT 2006

使用os.popen()的方法确实是python风格的正解,不过如楼主说的要用于shell脚本的 
管道付连接的话,可能并不是这个意思。
但事实上,shell的管道符|更好处理。管道符的作用是将之前的程序的标准输出和下 
一个程序的标准输入连接起来,也就是说,管道进来的数据就是来自标准输入的数 
据。
所以在你的a.py中,只要用读取标准输入的函数(raw_input()等)来直接读取就可以了 
~


On Thu, 03 Aug 2006 11:19:27 +0800, IQDoctor  
<huanghao.c at gmail.com> wrote:

> pipe()?
> 也许你想 os.popen(x, ["r"]["w"]) ?
>
> 在 06-8-3,曹翔<caoxiang at tomonline-inc.com> 写道:
>>
>>
>>
>> 如何在linux下读取管道进来的数据呢?
>>
>>
>>
>> 比如 ls | a.py 这样。
>>
>>
>>
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese at lists.python.cn
>> Subscribe: send subscribe to
>> python-chinese-request at lists.python.cn
>> Unsubscribe: send unsubscribe to
>> python-chinese-request at lists.python.cn
>> Detail Info:
>> http://python.cn/mailman/listinfo/python-chinese
>>
>>
>
>



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月03日 星期四 13:57

曹翔 caoxiang at tomonline-inc.com
Thu Aug 3 13:57:40 HKT 2006

可以给了例子么?


-----Original Message-----
From: python-chinese-bounces at lists.python.cn
[mailto:python-chinese-bounces at lists.python.cn] On Behalf Of IQDoctor
Sent: 2006年8月3日 11:19
To: python-chinese at lists.python.cn
Subject: Re: [python-chinese] 如何读取输入流

pipe()?
也许你想 os.popen(x, ["r"]["w"]) ?

在 06-8-3,曹翔<caoxiang at tomonline-inc.com> 写道:
>
>
>
> 如何在linux下读取管道进来的数据呢?
>
>
>
> 比如 ls | a.py 这样。
>
>
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request at lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
>


-- 
Best regrads,
IQDoctor




[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月03日 星期四 14:30

曹翔 caoxiang at tomonline-inc.com
Thu Aug 3 14:30:05 HKT 2006

明白了,多谢Leira :)


-----Original Message-----
From: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of Leira Hua
Sent: 2006年8月3日 13:50
To: python-chinese at lists.python.cn
Subject: Re: [python-chinese] 如何读取输入流

使用os.popen()的方法确实是python风格的正解,不过如楼主说的要用于shell脚本的
管道付连接的话,可能并不是这个意思。
但事实上,shell的管道符|更好处理。管道符的作用是将之前的程序的标准输出和下
一个程序的标准输入连接起来,也就是说,管道进来的数据就是来自标准输入的数
据。
所以在你的a.py中,只要用读取标准输入的函数(raw_input()等)来直接读取就可以了
~


On Thu, 03 Aug 2006 11:19:27 +0800, IQDoctor <huanghao.c at gmail.com> wrote:

> pipe()?
> 也许你想 os.popen(x, ["r"]["w"]) ?
>
> 在 06-8-3,曹翔<caoxiang at tomonline-inc.com> 写道:
>>
>>
>>
>> 如何在linux下读取管道进来的数据呢?
>>
>>
>>
>> 比如 ls | a.py 这样。
>>
>>
>>
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese at lists.python.cn
>> Subscribe: send subscribe to
>> python-chinese-request at lists.python.cn
>> Unsubscribe: send unsubscribe to
>> python-chinese-request at lists.python.cn
>> Detail Info:
>> http://python.cn/mailman/listinfo/python-chinese
>>
>>
>
>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

_______________________________________________
python-chinese
Post: send python-chinese at lists.python.cn
Subscribe: send subscribe to python-chinese-request at lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年08月03日 星期四 16:32

Xiao Lei Wu xiaoleiw at cn.ibm.com
Thu Aug 3 16:32:50 HKT 2006

Èç¹ûÊÇÕâ¸öÒâ˼µÄ»°£¬Ò²¿ÉÒÔ¿¼ÂÇʹÓÃ/devÏÂÃæµÄ±ê×¼ÊäÈë¡¢Êä³öÉ豸Îļþ

Best Regards,

Zachary Wu (Îâ°~ÀÚ)
Software Engineer, Enterprise Content Management FVT, IBM China Software
Development Lab
Tel: +86 10 82782244-3235. Fax: 82782244-2886 Tie Line: 915-2244-3235
Internet: xiaoleiw at cn.ibm.com
Notes ID: Xiao Lei Wu/China/Contr/IBM at IBMCN
Address: 8/F, Block A, Power Creative Building, No.1, East Road, Shang Di,
Beijing 100085, P.R. China

python-chinese-bounces at lists.python.cn дÓÚ 2006-08-03 13:49:32:

> ʹÓÃos.popen()µÄ·½·¨È·ÊµÊÇpython·ç¸ñµÄÕý½â£¬²»¹ýÈçÂ¥Ö÷˵µÄÒªÓÃÓÚshell½Å±¾
µÄ
> ¹ÜµÀ¸¶Á¬½ÓµÄ»°£¬¿ÉÄܲ¢²»ÊÇÕâ¸öÒâ˼¡£
> µ«ÊÂʵÉÏ£¬shellµÄ¹ÜµÀ·û|¸üºÃ´¦Àí¡£¹ÜµÀ·ûµÄ×÷ÓÃÊǽ«Ö®Ç°µÄ³ÌÐòµÄ±ê×¼Êä³öºÍ
ÏÂ
> Ò»¸ö³ÌÐòµÄ±ê×¼ÊäÈëÁ¬½ÓÆðÀ´£¬Ò²¾ÍÊÇ˵£¬¹ÜµÀ½øÀ´µÄÊý¾Ý¾ÍÊÇÀ´×Ô±ê×¼ÊäÈëµÄÊý
> ¾Ý¡£
> ËùÒÔÔÚÄãµÄa.pyÖУ¬Ö»ÒªÓöÁÈ¡±ê×¼ÊäÈëµÄº¯Êý(raw_input()µÈ)À´Ö±½Ó¶ÁÈ¡¾Í¿ÉÒÔ
ÁË
> ~
>
>
> On Thu, 03 Aug 2006 11:19:27 +0800, IQDoctor
> <huanghao.c at gmail.com> wrote:
>
> > pipe()?
> > Ò²ÐíÄãÏë os.popen(x, ["r"]["w"]) ?
> >
> > ÔÚ 06-8-3£¬²ÜÏè<caoxiang at tomonline-inc.com> дµÀ£º
> >>
> >>
> >>
> >> ÈçºÎÔÚlinux϶ÁÈ¡¹ÜµÀ½øÀ´µÄÊý¾ÝÄØ£¿
> >>
> >>
> >>
> >> ±ÈÈç ls | a.py ÕâÑù¡£
> >>
> >>
> >>
> >>
> >> _______________________________________________
> >> python-chinese
> >> Post: send python-chinese at lists.python.cn
> >> Subscribe: send subscribe to
> >> python-chinese-request at lists.python.cn
> >> Unsubscribe: send unsubscribe to
> >> python-chinese-request at lists.python.cn
> >> Detail Info:
> >> http://python.cn/mailman/listinfo/python-chinese
> >>
> >>
> >
> >
>
>
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060803/7aa114c3/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号