473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problems with os.system

Hi,

I am trying to run a python script that executes several other programs
on the bash (under linux) and reads some of the output of those
programs. This works fine for a couple of os.system() calls, but then
it does not work anymore. os.system() returns always -1, but when
executing exactly the same program directly on the linux-bash it works!

Could this be a memory problem? It happens when there is much data
stored in a python list. How can I check the memory usage in my python
script? Can I force python to execute the program on the bash? What can
I do?

I would very appreciate help in that.

Alexander

Sep 2 '05 #1
5 2445
On Fri, 2005-09-02 at 13:45 -0700, alexLIGO wrote:
Hi,

I am trying to run a python script that executes several other programs
on the bash (under linux) and reads some of the output of those
programs. This works fine for a couple of os.system() calls, but then
it does not work anymore. os.system() returns always -1, but when
executing exactly the same program directly on the linux-bash it works!

Could this be a memory problem? It happens when there is much data
stored in a python list. How can I check the memory usage in my python
script? Can I force python to execute the program on the bash? What can
I do?


Are you trying to read the output (stdout) of the program? If so you
should be using os.popen() not os.system().

Sep 2 '05 #2
No I read some other data files that has been created by the other
program. I am not interested in the stdout or err of that program...

Sep 2 '05 #3
alexLIGO wrote:
I am trying to run a python script that executes several other programs
on the bash (under linux) and reads some of the output of those
programs. This works fine for a couple of os.system() calls, but then
it does not work anymore. os.system() returns always -1, but when
executing exactly the same program directly on the linux-bash it works!
Try to break this down to a minimal testcase and then post that.

Also, I usually use the subprocess module instead of os.system these days.
How can I check the memory usage in my python
script? Can I force python to execute the program on the bash?


If bash is your shell, then os.system will call the program through a
bash subshell.
--
Michael Hoffman
Sep 2 '05 #4

Repeated calls to system() seem to cause no problem here.

I ran the following program:
import os

for i in xrange(10000):
assert os.system("true") == 0
in around 25 seconds, the 'for' loop completed, and the 'true' command
always returned 0 from system, as expected.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFDGM2IJd01MZaTXX0RAoLPAJ9WAgv0gd2oasbIk1XCcW 3n37OJ6wCgiMA+
nW5kqE1IZqbp7C9wMPd5d9E=
=1rIq
-----END PGP SIGNATURE-----

Sep 2 '05 #5
On Fri, Sep 02, 2005 at 01:45:42PM -0700, alexLIGO wrote:
Can I force python to execute the program on the bash? What can
I do?


os.system() is a wrapper on system(3), which invokes /bin/sh.

If you want to use a different shell, you can use
os.spawnv(os.P_WAIT, '/bin/bash', ['bash', '-c', command])
or even avoid the use of a shell altogether:
os.spawnvp(os.P_WAIT, 'myprogram', ['myprogram', '-arg1', 'arg2'])

Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFDGRVrJd01MZaTXX0RAiUWAJ4j/qcZGVJCVxH1jgVDGp07HS5AdgCfUaaO
kB2XFeUhrFzAwx58pk0S7Rg=
=qHQV
-----END PGP SIGNATURE-----

Sep 3 '05 #6

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

Similar topics

9
by: Eva | last post by:
Hi, I wanted to know how i can enter values into a specific column of a listview. I have tried the following code but this seems to enter all my values into the first column!!! Can anyone...
0
by: Jesper Stocholm | last post by:
I am using the example as the basis for an application I am currently writing. The setup consists of two applications (client and server) that talk to each other thru TCP. I have no problems...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
17
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
2
by: Joel D. Kraft | last post by:
I've been very happy with the performance and new features of my site since we converted to ASP.NET 2.0 beta 2. I have noticed a couple of interesting problems, though, which I am trying to...
0
by: neoret | last post by:
Hello. I have developed an application (an office addin).The application works fine with no error messages on my devoping machine (that machine is not connected to any domains). I have...
0
by: neoret | last post by:
Hello. I have developed an application (an office com addin).The application works fine with no error messages on my devoping machine (that machine is not connected to any domains). I have...
9
by: =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post by:
I am using VC++ 6.0 (with SP5 installed). When using WinXP this is with SP2 installed. I am developing an instrumentation system comprising a set of networked PCs connected using TCP/IP TCP links....
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...
0
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...

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.