C++ to call python script to handle emailing

On a server I have a C++ program which takes some input and writes some output to a file. After the file is generated, I want to send an email to a person with the corresponding link to the file.

I'd rather avoid dealing with SMTP from C++ itself, so I thought about having C++ using a system call to execute a python script, which would in turn handle the emailing process.

In C++:

system("python emailer.py foo@bar.com filetodownload.txt");

In Python:

import sys
email = sys.argv[1]
file = sys.argv[2]
// handle SMTP emailing...

I have a question about this simple approach. The C++ program is multithreaded, so there may be more than one thread wanting to call the python script to send an email. Is this a concern? Would one (again simple) solution be having a mutex variable in the C++ program which allows only one thread to call the python script at a time? Also, if there are better ways to go about accomplishing this task please let me know.

Answers


From what you've shown I don't see any shared resource that would require any multi-threaded synchronisation. Each system call to python will result in a separate process.


Need Your Help

Passing a class object as an argument in C++

c++ class arguments

Suppose I had a class named foo containing mostly data and class bar that's used to display the data. So if I have object instance of foo named foobar, how would I pass it into bar::display()? Some...

How to create maven modulized project

maven maven-plugin maven-3

I want to create maven multi module project, but it should not like normal module project. My requirement is divide web project in to many parts and some module contents common pages, when building

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.