Save the output of a command in a string in linux using python
Posted
by
user1657901
on Stack Overflow
See other posts from Stack Overflow
or by user1657901
Published on 2012-09-09T09:35:17Z
Indexed on
2012/09/09
9:37 UTC
Read the original article
Hit count: 265
python
I am using Fedora 17 xfce and I am programming in Python 2.7.3. Fedora uses a package manager called yum. I have a python script that searches for packages like this:
import os
package = raw_input("Enter package name to search: ")
os.system("yum list " + package)
So I want python to check if in the output of this command exists the words "No matching packages to list". I checked a similar question and I tried some methods [http://stackoverflow.com/questions/2502833/python-store-output-of-subprocess-call-in-a-string][1] but the string contained only the first line of the output.
Thanks in advance
© Stack Overflow or respective owner