Store Os.system Result In Variable
hello guys i'm wondering how to store os.system result in variable as we know it's return 0 so i'm wondering what i should do to store the result and second question : how to get
Solution 1:
import os
from subprocess import *
defrun_cmd(cmd):
p = Popen(cmd, shell=True, stdout=PIPE)
output = p.communicate()[0]
return output
As for the second question, see http://www.cyberciti.biz/tips/read-unixlinux-system-ip-address-in-a-shell-script.html
Solution 2:
Since you're first question is a python question, here is how to get the IP address in linux using python:
import socket
import fcntl
importstruct
ifname='eth0'
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
address = socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
Post a Comment for "Store Os.system Result In Variable"