473,473 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Python os.popen in Linux

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
Jul 18 '05 #1
2 7644
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

Jul 18 '05 #2
perhaps you'd find commands.getoutput useful instead?
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the...
18
by: qwweeeit | last post by:
Hi all, when I moved from Windows to Linux I choosed Python as my language of reference and as GUI, Qt (not much investigated up to now). Till now I didn't regret but one thing: Python can't act...
16
by: diffuser78 | last post by:
I want to write a python program and call OS specific commands in it. So basically, instead of typing in on the command line argument I want to have it in a python program and let it do the action....
14
by: Rochester | last post by:
Hi, I just found out that the general open file mechanism doesn't work for named pipes (fifo). Say I wrote something like this and it simply hangs python: #!/usr/bin/python import os
0
by: dan.jakubiec | last post by:
I'm trying to write a Python app which accepts a socket connection and then spawns another Python process to handle it. I need it to run under both Linux and Windows. I have it working under...
17
by: krishnakant Mane | last post by:
hello all, I am stuck with a strange requirement. I need a library that can help me display a pdf file as a report and also want a way to print the same pdf file in a platform independent way....
7
by: Jonathan Fine | last post by:
Hello My problem is that I want a Python 2.4 module on a server that is running Python 2.3. I definitely want to use the 2.4 module, and I don't want to require the server to move to Python...
8
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I would like to find out how I can launch an independent Python program from existing one in a cross-platform way. The result I am after is that a new terminal window should open (for io...
3
by: Doru Moisa | last post by:
Hello, How can I capture the output of a long runnning process which I open with popen() ? I tried reading line by line, char by char, but the result always comes when the process finishes. (I...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.