Does anyone know how to use the subprocess.call to assign the ouput of a command to a string.
At the moment it only assigns the return code ??
>>> hostname = call(["hostname", "-d"])
lon3.corp.rackspace.com
>>> print hostname
0
Thanks,
Does anyone know how to use the subprocess.call to assign the ouput of a command to a string.
At the moment it only assigns the return code ??
>>> hostname = call(["hostname", "-d"])
lon3.corp.rackspace.com
>>> print hostname
0
Thanks,
Easiest way could be to use Gribouillis Cmd class: http://www.daniweb.com/software-development/python/code/257449
For hostname, I think you can find it through environment variable: http://www.comptechdoc.org/os/linux/usersguide/linux_ugenvironment.html
import os
print(os.environ.get('HOSTNAME'))
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.