473,395 Members | 1,689 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,395 software developers and data experts.

os.system questions

Hi;
I have a couple bugs to work out in the below script; namely, I don't know
how to capture the result of an os.system command, nor am I convinced that
the call to os.system actually results in the execution of the command. Here
is the script:

#!/usr/local/bin/python
import re, os

def freshReboot():
up = os.system("uptime")
if re.search('day|hour', up):
pass
else:
first = up
tup = re.split('min', up)
first = tup[0]
n = len(first)
char = first[n-3:n-2]
if re.match(' ', char):
os.system("/usr/local/etc/rc.d/zz_mysql_starter_script.sh")
Here are my problems:

up = os.system("uptime")
How do I assign the output of "uptime" to the variable "up"?

os.system("/usr/local/etc/rc.d/zz_mysql_starter_script.sh")
When I substitute a test variable for "up", I don't get this script to
actually run. Everything else is tested and works. Why won't this script
run?

TIA,
Eric

__________________________________________________ _______________
It’s tax season, make sure to follow these few simple tips
http://articles.moneycentral.msn.com...d=HMMartagline

Mar 31 '07 #1
2 1502
Eric Price schrieb:
up = os.system("uptime")
How do I assign the output of "uptime" to the variable "up"?
| >>print os.system.__doc__
| system(command) -exit_status
|
| Execute the command (a string) in a subshell.

os.system returns the exitcode of the given command. To get the output
try os.popen to os.popen4 or the commands lib.

Thomas
Mar 31 '07 #2
In article <ma***************************************@python. org>,
Eric Price <so***********************@hotmail.comwrote:
>
I have a couple bugs to work out in the below script; namely, I don't
know how to capture the result of an os.system command, nor am I
convinced that the call to os.system actually results in the execution
of the command. Here is the script:
Although you've already figured out the problem, I'll just make the
standard recommendation for the subprocess module, assuming you have
Python 2.4 or later.
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

Need a book? Use your library!
Mar 31 '07 #3

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

Similar topics

5
by: jose luis fernandez diaz | last post by:
Hi, In the program below: #include <stdio.h> #include <stdlib.h> #include <errno.h> using namespace std; int main()
5
by: DFS | last post by:
I've written several survey systems in which the majority of the questions have the same or similar responses (Yes/No, True/False, scale of 1 - 5, etc). But this latest survey system I'm working...
5
by: Abraham Lopez | last post by:
Hi.. Is there a way to convert a System.Array to XML... If you know thanks very much... if you don't... Please do not respond stupid things like " Yes -- many ways."
20
by: SR | last post by:
Hi, I need to read the output from a system( ) function within a C program. The function however only returns the exit status. How can I read what system( ) sends to stdout ? (is there a simpler...
4
by: The Spoon | last post by:
I am looking for functions that can be used to automatically update the system date and time on an NT based system, resulting from manually entered date and time values input by an operator via a...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
2
by: questions? | last post by:
I use os.system to call a display program, e.g. os.system(displayblah blah) to call display. the program starts and display things I wanted. When I kill display, somehow the python program don't...
4
by: =?Utf-8?B?TXJzIE5vYWNo?= | last post by:
Hi to all you wonderful people, have read some of the answers re:- system restore, but non of the questions seem to fit my problem. Windows XP Home Edition Version 2002 Service Pack 2 When I...
5
by: pefok | last post by:
Hello everyone, One of my course works is to implement a java based quiz system. the program consists of two modules one for the teacher to create, set questions , answers and the number of...
16
by: Paul Schwann | last post by:
Hi group, I am relatively new to C# (although I have a lot of programming excperience in other languages like Java and C). Currently I am searching for a solution to this problem: Suppose you...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.