Python os.popen in Linux

Discussion in 'Python' started by Sami Viitanen, Sep 29, 2003.

  1. 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
     
    Sami Viitanen, Sep 29, 2003
    #1
    1. Advertising

  2. Sami Viitanen

    Peter Otten Guest

    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
     
    Peter Otten, Sep 29, 2003
    #2
    1. Advertising

  3. Sami Viitanen

    Guest

    perhaps you'd find commands.getoutput useful instead?
     
    , Oct 2, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-15?Q?J=F6rg?= Maier

    python on windos os.popen and standart in and out

    =?ISO-8859-15?Q?J=F6rg?= Maier, Jul 27, 2003, in forum: Python
    Replies:
    2
    Views:
    347
    =?ISO-8859-15?Q?J=F6rg?= Maier
    Jul 29, 2003
  2. Robin Siebler
    Replies:
    6
    Views:
    545
  3. damacy
    Replies:
    5
    Views:
    668
    damacy
    Jun 24, 2006
  4. Replies:
    2
    Views:
    1,905
    Nick Craig-Wood
    Aug 24, 2006
  5. File.popen/IO.popen

    , May 20, 2006, in forum: Ruby
    Replies:
    1
    Views:
    276
    Robert Klemme
    May 20, 2006
Loading...

Share This Page