python subprocess reading terminal output and reply using PyQt4 message pop up
Question: Hi im making a program to check adb devices in python

I cant make a pop up window please correct my code.

import sys import subprocess from PyQt4 import QtGui, QtCore

ad = subprocess.check_output(["adb", "devices"])

    
    
    class Example(QtGui.QWidget):
        def __init__(self):
            super(Example, self).__init__()
    
            self.initUI()
    
        def initUI(self):
    
            QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
    
    
            btn = QtGui.QPushButton('Check Device', checkadb(ad))
            btn.resize(135, 30)
            btn.move(50, 10)
    
            self.setGeometry(250, 250, 400, 400)
            self.setWindowTitle('Tooltips')
            self.show()
    
    def clicked(*args):
        QtGui.QMessageBox.about(QtGui, "No Device Found")
    
    def clicked2(*args):
        QtGui.QMessageBox.about(QtGui, "Device Found")
    
    def checkadb(ad):
        if len(ad) <= 27:
            clicked()
    
    elif len(ad) > 27:
        clicked2()
    
    def main():
    
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
    
    if __name__ == '__main__':
        main()
    


Answer: Might you be looking for
[`subprocess.check_output()`](http://docs.python.org/2/library/subprocess.html#subprocess.check_output)?
Your use of `subprocess.call()` will give you the return code of the command
executed (a `0` indicates normal exit status).

If your result was in fact the string `"List of devices attached\n\n0"` then
you should use `.splitlines()` to split the string by each line into a list,
which would be `["List of devices attached", "", "0"]`. This would be in the
case that despite what I am lead to believe by the code in your question, you
are returning the correct result, i.e. `0`.

