import subprocess from time import gmtime, strftime cmd = "tnsping alias.fixer" def system_call(cmd, params=None, inshell=False, communicatestr='\n' * 10): cmds = cmd try: p = subprocess.Popen(args=cmds, shell=True, bufsize=4096, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdoutdata, stderrdata = p.communicate(communicatestr) if stderrdata: print strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' - ' + stderrdata else: print stdoutdata except subprocess.CalledProcessError as e: print strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' - ' + e.output pass while 1 == 1: system_call(cmd)