os.system questions

E

Eric Price

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/Taxes/PreparationTips/PreparationTips.aspx?icid=HMMartagline
 
?

=?windows-1252?Q?Thomas_Kr=FCger?=

Eric said:
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
 
A

Aahz

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top