473,667 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

baffling os.system behavior - differs from command line

It goes like this:
Im converting a perl script that executes a command on each result of
a directory listing. In perl, all is well. In Python, using
approximately
the same logic creates a seemingly random problem I can't pin down.
I hesitated to ask this question since it's so Slackware
Linux-centric,
and im new to Python. It's hard to ask in a generic way, but im out of
options...

The command is Slackware's package creation utility, makepkg. It uses
the
current working directory as package source and takes a filename as an
argument to output the newly created package to. Makepkg is
essentially
a tarball creator, wrapped in a nice command. Simple stuff. Here is my
code:

I have a for loop that reads a file list, like so:
pkg_srcdir = '/packages_source '
pkg_dir = '/packages_tgzs'
ls = os.listdir(pkg_ srcdir)

for name in ls:
build_src = pkg_srcdir + '/' + name
new_filename = pkg_dir + '/' + name + '.tgz'

# Valid directory?
if not os.path.isdir(b uild_src):
sys.exit("\nInv alid directory \'" +
pkg_srcdir + "\'\n")

# Go into the new directory
try: os.chdir(build_ src)
except os.error, value:
sys.exit("\nInv alid directory: \'" +
build_src + "\': " + value[1])

# I then execute the command on each result,
like so:
# new_filename is correctly assembled, which i
can verify
# from printing it out on each loop iteration
os.system('/sbin/makepkg --chown n --linkadd y
' + new_filename)

When all is done running, which take a good 7 minutes, I get varied
results.
It looks like its working... pauses, has lots of disk activity on the
drive
(verified with ps and vmstat), but in the end only a couple of
packages are
created. I can actually watch the output of makepkg and see it
creating the
tarballs. Here is the truly whacky part: Changing pkg_dir to anything
else,
say /tmp/beavis, will create the packages correctly for a while, then
mysteriously stop with no warning or change to the script - just run
it a
few times and it stops working.

Im running as root, so its not a permission problem - its far to
erratic
anyway.

I dont think this problem has anything to do with os.system, per say,
since it also happens with os.popen.

I thought it might be a buffering problem, so i tried using Python's
-u
switch and flushing stdout with sys.stdout.flus h() - no go.

I tried sleeping for long periods of time in each loop iteration - no
go.

I tried writing each individual makepkg command out to a file and
running it with perl, doing all the proper filehandling. I also
tried bash for kicks - no go

In the end, I put an ampersand at the end of the makepkg command, like
so:
os.system('/sbin/makepkg --chown n --linkadd y ' +
new_filename + ' &')

This sort of works: it creates 95% of the packages most of the time -
results varies. It always seems to leave out the same packages.
The packages it misses are in the middle of the list, so its not
just skipping the first or the last few.

Im baffled.

Any ideas?
Jul 18 '05 #1
1 1949
In article <60************ **************@ posting.google. com>,
ev**@pondie.com (Ben Floyd) wrote:
....
The command is Slackware's package creation utility, makepkg. It uses
the
current working directory as package source and takes a filename as an
argument to output the newly created package to. Makepkg is
essentially
a tarball creator, wrapped in a nice command. Simple stuff. Here is my
code:

I have a for loop that reads a file list, like so:
pkg_srcdir = '/packages_source '
pkg_dir = '/packages_tgzs'
ls = os.listdir(pkg_ srcdir)

for name in ls:
build_src = pkg_srcdir + '/' + name
new_filename = pkg_dir + '/' + name + '.tgz'

# Valid directory?
if not os.path.isdir(b uild_src):
sys.exit("\nInv alid directory \'" + pkg_srcdir + "\'\n")

# Go into the new directory
try: os.chdir(build_ src)
except os.error, value:
sys.exit("\nInv alid directory: \'" + build_src + "\': " + value[1])

# I then execute the command on each result, like so:
# new_filename is correctly assembled, which i can verify
# from printing it out on each loop iteration
os.system('/sbin/makepkg --chown n --linkadd y ' + new_filename)


Well, I don't know. In casual inspection I don't notice
anything obviously wrong, but then for all I know this
isn't the exact code that has the problem anyway. What
I could suggest is substitute your own shell script for
makepkg, something that prints out its arguments, current
working directory and whatever you think might be interesting.
The object is to find out exactly what you're asking makepkg
to do, since that is evidently a problem.

Actually a Python program might be a little better, because
"print sys.argv" gives you less ambiguous information than
"echo $*", more like "for arg do echo $arg; done" but on
one line.

The two usage points that occur to me are
1. chdir() affects Python module path resolution. If you
chdir to a directory with an "os.py", that would be an
obvious if unlikely problem, but also some installations
rely on Python's library finding heuristics in a way
that is kind of fragile. I may be wrong about that,
I don't even want to think about wasting time on this
misguided feature.

2. system() can be replaced with spawnv() for an increase
in command parameter list reliability. What if some
file has spaces? In spawnv(), you don't care, but in
system() it's your job to quote it. This is also a
security related issue.

Donn Cave, do**@u.washingt on.edu
Jul 18 '05 #2

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

Similar topics

2
16198
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643 (possibly white) Can anyone tell me how to convert these colours to either RGB colours or the Long number used by Access. Black is 0 and White is 16777215 ...
4
1529
by: Steve | last post by:
I'm currently running into a problem, and I have no idea what to make of it. I have a class with nested clases and static properties that I'm using to store configuration information using a custom configuration section. When my code accesses one of the static properties the static constructors are fired, and the code goes in and pulls the data from the configuration section. In the current instance, I'm getting a connection string....
1
6868
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by itself (asp.net recycled?); it also can be solved by restarting IIS. Any ideas what cause(s) this to happen? System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr) at...
5
9642
by: petro | last post by:
Hello all, My asp.net web application works on my machine but I get the following error on our test web server, There is only one oracle home on the test server. Does anyone know how to resolve this error? Oracle error occurred, but error message could not be retrieved from Oracle. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the...
7
7003
by: WALDO | last post by:
I wrote a console application that basically consumes arguments and starts other command line apps via System.Process. Let's call it XCompile for now. I wrote a Visual basic add-in that does pretty much the same thing to XCompile. Let's call it MyAddin. XCompile collects information to send to vbc.exe. When it comes across any arguments that are file paths, it wraps them in quotes. For example: Dim prms As String
6
5991
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to assign a value to them. I wanted to trap for this exception in a subclass using super but it doesn't happen. I have read Guido's tutorial on new style classes and Shalabh's tuturial on new style attributes and methods, and thought I understood...
9
2225
by: Christopher Benson-Manica | last post by:
According to 7.20.4.5 of n869, system() can report whether the host environment has a command processor (when passed a null pointer). Obviously, if there is a command processor, non-null string arguments to system() are passed to it. However, the text doesn't specifically state what occurs when there is no command processor to pass strings to. Presumably this is nothing, but should that be obvious from the text? -- C. Benson Manica ...
3
1670
by: Scotty | last post by:
I'm a C++ novice and need help figuring out some odd behavior I've encountered. Here's the situation: I create a class and have its constructor store a random number in a private "number" variable. The class also has a "getNumber()" function that returns its stored number. A function in the program creates five objects of this class and five pointers to these objects, the latter of which are stored in a global array. When "getNumber()"...
12
3474
by: tom_kuehnert | last post by:
Hi! I'm trying to execute a program using system(). The program itself is located in some path which might contain whitespaces. Simple solution would be this: system("\"C:\A B\C.exe\""); but now this program also has parameters which need to be passed (again with paths containing whitepaces)
0
8365
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8788
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6203
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.