pipes like perl
max(01)*
max2 at fisso.casa
Tue Aug 23 18:53:34 EDT 2005
max(01)* wrote:
> infidel wrote:
>
>> Here's one technique I use to run an external command in a particular
>> module:
>>
>> stdin, stdout, stderr = os.popen3(cmd)
>> stdin.close()
>> results = stdout.readlines()
>> stdout.close()
>> errors = stderr.readlines()
>> stderr.close()
>> if errors:
>> raise Exception(''.join(errors))
>>
>> Maybe this will get you going in a better direction?
>>
>
> yeah thanks!
>
> i translated as:
>
> .....
> import os
> .....
> CMD_STDIN, CMD_STDOUT, CMD_STDERR = \
> os.popen3("*some_system_command*", "r")
> if not CMD_STDERR.readlines():
> ...
> *do_something*
> ...
> for answer in CMD_STDOUT:
> print answer,
> ...
> *do_something_more*
> ...
> else:
> ...
> *do_something_else*
> ...
> CMD_STDIN.close()
> CMD_STDOUT.close()
> CMD_STDERR.close()
> .....
but... i see it doesn't work for some commands, like "man python" (it
gets stuck on the "if" line)...
how come?
More information about the Python-list
mailing list