Python os.popen in Linux

S

Sami Viitanen

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 ?

Example of "os.popens" that were not executed correctly:

# Freezes files one at the time
def sfnFreezeFiles(sModFiles,sTagOld):
lModFiles = string.split(sModFiles) # Makes list out of
string
x = 0
while x < len(lModFiles): # While
files in list
iFilePoint = string.rfind(lModFiles[x],'/',1) # Seeks
last '/' -char from string
sModFile = lModFiles[x]
sDir = sModFile[:iFilePoint] #
Directory = from start to last '/'
sModFile = sModFile[iFilePoint+1:] # File =
from last '/' to end of string
ColorPrint.fnPrintExecute('Freezing: %s %s' % (sDir,sModFile))
sCurrentDir = os.getcwd() # Get
current working directory
os.chdir(sDir) # Change
directory
os.popen('cvs update -A %s' % sModFile) # Remove
sticky-tag from file <----- OS.POPEN
os.popen('cvs ci '+sModFile) #
Checkin file <----- OS.POPEN
os.chdir(sCurrentDir) # Change
directory back
x = x+1
return len(lModFiles)


Thanks in advance. --SV
 
P

Peter Otten

Sami said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top