Strange os.popen() behavior

Carsten Gaebler clpy at snakefarm.org
Tue Jul 3 12:19:15 EDT 2001


Hi there!

I have a problem with a script that reads the contents of /etc/passwd from
a remote host. It doesn't always seem to read all lines:

<test.py>
#!/usr/bin/python

import os

for i in range(5):
    pipe = os.popen("ssh -q root at remotehost cat /etc/passwd")
    passwd = pipe.readlines()
    pipe.close()
    print len(passwd)
</test.py>

Here's the output:

969
72
969
325
969

If I enter the SSH command in a shell I always get all 969 lines of
/etc/passwd (the file does not change over time). Any clues?

I am using Python 2.1, OpenSSH 2.9p1 (client), OpenSSH 2.5.2p2 (server).

Regards
Carsten.



More information about the Python-list mailing list