Re: os.system questions



On 3/31/07, Eric Price <soyouthinkimgonnalikethis@xxxxxxxxxxx> wrote:
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?

os.system doesn't allow you to get the output of the program, use
os.popen instead.
example:
import os
up = os.popen('uptime').readlines()

Cheers,

--
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.
.



Relevant Pages

  • Re: File opeartions help
    ... system; command to the file. ... Anyway, to answer your 1,000,000th question about this script (confetti ... maybe you should capture the output, and, write ...
    (perl.beginners)
  • Re: redirecting output from telnet
    ... In article, Will Hartung wrote: ... > 'script' command. ... Actually, it will capture everything printed on the screen, so it will ...
    (comp.unix.solaris)
  • Converting terminal session caputure to printable characters
    ... I've used the "script" command to capture a terminal session. ...
    (SunManagers)
  • Re: Assinging output to the variable
    ... > I have this script: ... > However i need to capture the result of the last command into the variable, ... spammers hate this program because they can't beat it ...
    (comp.unix.shell)
  • xp_cmdshell
    ... i'm trying to capture a key value and place it in a table. ... I can get the value in a script, ... execute xp_cmdshell using the code and capture the output ... :: line above for command ...
    (microsoft.public.sqlserver.programming)