473,941 Members | 17,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2471
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)

iD8DBQFDGM2IJd0 1MZaTXX0RAoLPAJ 9WAgv0gd2oasbIk 1XCcW3n37OJ6wCg iMA+
nW5kqE1IZqbp7C9 wMPd5d9E=
=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)

iD8DBQFDGRVrJd0 1MZaTXX0RAiUWAJ 4j/qcZGVJCVxH1jgVD Gp07HS5AdgCfUaa O
kB2XFeUhrFzAwx5 8pk0S7Rg=
=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
6141
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 please help me out on this?? hers my code so far.....
0
1298
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 with sending information back and forth, but I have problems _containing_ the data sent from the client to the server. In the class I instantiate/declare a StringBuilder to collect the data as it comes thru the socket
10
2437
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) ComboBox.SelectedValue = db_value; If the db_value was not included in the ComboBox value list the ComboBox.SelectedIndex used to return -1, Now the very same code is
17
2526
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 'Button19' of type 'Button' must be placed inside a form tag with runat=server Can the IDE not do what it is supposed to do. It seems that it is a fight to make it do anything or did I do something wrong? It would seem silly to have to create a...
21
3002
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 updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not impossible for a single client to request 100 plus pages in one session - as each page is requested it is...
2
5710
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 figure out. I can't confirm that they didn't exist under 1.1, but I didn't notice them at that time. My error handling is configured as follows: - In IIS, 404 errors are mapped to /site/error/404.aspx. - "Verify that file exists" is ON for .aspx...
0
1722
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 problems getting this application to run on a computer where the user is on a domain (as in a big company where you log on to the company domain).
0
1150
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 problems getting this application to run on a computer where the user is on a domain (as in a big company where you log on to the company domain). The funny thing is that the application works fine in outlook. But not
9
2422
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. Communications on the Windows PCs use a class derived from CAsyncSocket(). I have written client and server versions of my software for use on the appropriate PCs. I am also using communicating with a legacy DOS based system, with the software...
34
5401
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 "<pyshell#10>", line 1, in <module> os.startfile("C:\Documents and Settings\Alex\My Documents\My
0
10134
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11530
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...
1
11295
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9858
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7389
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
6079
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
6298
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4449
muto222
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.