NT related question (not really Python related)

Adrian Eyre a.eyre at optichrome.com
Fri Oct 22 10:22:12 EDT 1999


> I often execute UNIX command from Python scripts, redirecting the output
of
> the command to a text file. Then I load the text file, scan it, and do
some
> processing.

Instead of redirecting to a file, why not use os.popen():

import os, string, sys

f = os.popen("ps -a")
l = f.readlines()
f.close()
for i in l[1:]:
	j = string.split(i)
	if j[2] == sys.argv[1]:
	os.kill(j[0])


> Anyway, that kind of stuff is easy to implement and convenient for me. The
> problem is that, sometimes, on *some* NT machines, the file redirection
> doesn't work. It doesn't work at all, not even outside Python (i.e. on the
> command line). As a QA team member, I have access to dozens of machines,
but
> only two have the problem from time to time. All have NT4 SP5.

I have never has problems with redirection before. The only thing I can
think
of is that the program is writing to stderr instead of stdout, or it could
be
a problem with the shell. Have you tried os.popen() on these machines?

--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233  Fax: +44 1483 760 644
http://www.optichrome.com
--------------------------------------------





More information about the Python-list mailing list