[Twisted-Python] Using StandardIO and pipes.
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Tue Aug 14 04:40:17 MDT 2012
On 07:51 am, lacrima.maxim at gmail.com wrote:
>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
Command line arguments aren't really anything like standard input.
Command line arguments are available immediately, synchronously, in
their entirety. They are tokenized into a list of strings, and there
are limits imposed on what bytes can appear in those strings.
Standard input can only be read a little at a time, perhaps throughout
the duration of the entire process, and attempting to do so may involve
blocking or dealing with complicated, platform-specific non-blocking
APIs. Standard input can contain any bytes and arrives as a stream, not
as a reliably tokenized list of strings.
Twisted includes no support for treating stdin and command line
arguments in a similar fashion.
After you look up the command line arguments from sys.argv, just use the
values. There would seem to be little point in trying to shove them
through a protocol object.
Jean-Paul
More information about the Twisted-Python
mailing list