I'm trying to make the following code work: import os, sys app=['host1', 'host2', 'host3'] for i in app: os.system('nmap -p 22 -P0 %s | grep open 2>&1 > /dev/null && echo "%s up" I've tried many different iterations of the os.system call, how to make this work? TIA