import subprocess from time import gmtime, strftime # cmd = "tnsping alias.fixer" cmd = ['ping', '8.8.8.8', '-c 10'] def system_call(cmd): cmds = cmd # commstr not used. # Streams close at communicate() automatically. #commstr = '\n\n' try: sub = subprocess.Popen(args=cmds, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = sub.communicate() if stderr: print strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' - ' + stderr else: print stdout except subprocess.CalledProcessError as e: print strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' - ' + e.output pass while 1 == 1: system_call(cmd)