def execWait(cmd, outfile=None, timeout=0):
result = ""
env = os.environ
proc = subprocess.Popen(cmd, executable='/bin/bash', env=env, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
if timeout:
timer = threading.Timer(timeout, proc.kill)
timer.start()
result = proc.communicate()[0]
if timeout:
if timer.is_alive():
timer.cancel()
if outfile:
if Utils.fileExists(outfile):
print("FILE ALREADY EXISTS!!!!")
else:
tmp_result = "\033[0;33m(" + time.strftime(
"%Y.%m.%d-%H.%M.%S") + ") <pentest> #\033[0m " + cmd + Utils.newLine() + Utils.newLine() + result
Utils.writeFile(tmp_result, outfile, 'ab')
return result
评论列表
文章目录