Python os.popen in Linux
Peter Otten
__peter__ at web.de
Mon Sep 29 13:13:17 EDT 2003
Sami Viitanen wrote:
> Hello,
>
> I was using os.popen function to get CVS command output to string from
> script..
>
> Same commands worked well with Windows, but Linux seems to have problem
> with those. Whole CVS commands seem to froze or given commands aren't
> executed right
> at all. I had to replace os.popen commands with os.system. os.system
> commands just
> print additional information to screen that is not necessary at all.
>
> Any ideas what may cause this ?
I think os.system() is the way to go. You should *not* suppress any error
messages, but if you must, simply redirect to /dev/null. However, it would
be worth the effort to search for some existing Python/CVS interface that
performs some real error handling.
<untested>
def sfnFreezeFiles(sModFiles):
lModFiles = sModFiles.split()
sCurrentDir = os.getcwd()
try:
for path in lModFiles:
sDir, sModFile = os.path.split(path)
ColorPrint.fnPrintExecute('Freezing: %s %s' % (sDir, sModFile))
os.chdir(sDir)
os.system('cvs update -A %s 2>/dev/null' % sModFile)
os.system('cvs ci %s 2>/dev/null' % sModFile)
finally:
os.chdir(sCurrentDir)
return len(lModFiles)
</untested>
Off topic: I suppose you were exposed to VB too long :-)
I've taken time to clean up your function a bit, your comment style is
obscuring the code rather than helping the reader.
Peter
More information about the Python-list
mailing list