[Twisted-Python] Using StandardIO and pipes.

Maxim Lacrima lacrima.maxim at gmail.com
Tue Aug 14 03:51:31 EDT 2012


Hi Drew,

I was referring to the example attached by Glyph. His example helped me to
properly handle stdin in my code. In addition to stdin I want to handle
command line arguments, so I want to be able to do this:
$ echo foo | ./check.py
and this:
$ ./check.py foo

I think `main` function should look something like this:

def main():
    if sys.stdin.isatty():
        # we are connected to terminal
        args = sys.argv[1:]
        # ....
        # What should I implement to be able to speak EchoItemProtocol???
        # ....
    else:
        # we are connected to stdin
        stdio.StandardIO(EchoItemProtocol())
    reactor.run()

I am new to Twisted, so I don't know a proper term for a class I need to
implement (is it a factory, a transport, an endpoint etc.???) to be able to
speak EchoItemProtocol?
Is this a valid approach at all?

In case you can't find previously attached example, I have attached it
again.


On 14 August 2012 04:09, Drew Smathers <drew.smathers at gmail.com> wrote:

> On Mon, Aug 13, 2012 at 8:18 AM, Maxim Lacrima <lacrima.maxim at gmail.com>
> wrote:
> > Hi everyone!
> >
> > Thanks for the help! I used an attached example and after implementing
> > IHalfCloseableProtocol it works! Thanks a lot!
> >
>
> Hi Maxim,
>
> Sorry I do not have an immediate answer to your question but just
> wanted to let you that I don't see the file attachment mentioned
> above. You might have forgotten this.
>
> -Drew
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



-- 
with regards,
Maxim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20120814/6be8bb61/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check.py
Type: application/octet-stream
Size: 1233 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20120814/6be8bb61/attachment.obj 


More information about the Twisted-Python mailing list