Skip to content

Instantly share code, notes, and snippets.

Last active July 6, 2018 17:04
What would you like to do?
Python script to run an exe, capture the logs and email them as attachment
#Author: Shivendra Agarwal
#Year: 2018
#Title: Python script to run an executable, capture the logs and email them as attachment
# Script to run the tests
import subprocess, sys
def IsPlatformWin():
return (sys.platform == "win32")
command = R'GoogleTest' # path of executable you want to run
if (IsPlatformWin):
command+= '.exe'
p = subprocess.Popen(command,stdout=subprocess.PIPE)
(stdoutdata, stderrdata) = p.communicate()
print stderrdata
content = stdoutdata
# Script to parse above content and send a mail if any failure.
status = content.partition('Global test environment tear-down')[2]
print (status)
if '[ FAILED ]' in status:
# Script to send a mail in case of failure
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
msg = MIMEMultipart()
msg['From'] = '' # fix the address
msg['To'] = '' # fix the address
msg['Subject'] = 'GoogleTest failure report'
body = status
msg.attach(MIMEText(body, 'plain'))
part = MIMEBase('application', "octet-stream")
part.add_header('Content-Disposition', 'attachment; filename="log.txt"') # name of file
mailServer = smtplib.SMTP('', 587)
mailServer.login(msg['From'], 'password') # password of from
# if you face issue while logging in gmail
mailServer.sendmail(msg['From'], msg['To'], msg.as_string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment