Replaced the system() calls by c++ code