Python TypeError: iteration over non-sequence on simple list
Question: 
    import os
    
    test = os.system("ls /etc/init.d/ | grep jboss- | grep -vw jboss-")
    for row in test:
        print row
    

For some reason this gives the TypeError: iteration over non-sequence error on
this.

When I do a print test without the for loop, it gives a list of the jboss
instances, plus a "0" at the bottom.. The heck?


Answer: `os.system()` returns the _exit code_ of the process, _not_ the result of the
`grep` commands. This is always an integer. In the meantime, the output of the
process itself is not redirected, so it writes to `stdout` directly (bypassing
Python).

You cannot iterate over over an integer.

You should use the [`subprocess.check_output()`
function](http://docs.python.org/2/library/subprocess.html#subprocess.check_output)
instead if you wanted to retrieve the stdout output of the command.

In this case, you'd be better off using `os.listdir()` and code the whole
search in Python instead:

    
    
    for filename in os.listdir('/etc/init.d/'):
        if 'jboss-' in filename and not filename.startswith('jboss-'):
            print filename
    

I've interpreted the `grep -vw jboss-` command as filtering out filenames that
_start_ with `jboss`; adjust as needed.

