Why getting g++ not recognized as a command while running subprocess in python?

I have an online ide which takes code and language from the user and upon submitting the server has to execute the file. I have g++ installed on my system still upon execution I get the following error in subprocess module:

'g++' is not recognized as an internal or external command,
operable program or batch file.
'.' is not recognized as an internal or external command,
operable program or batch file.

The function for file execution is :

def execute_file(file_name,language):
    if(language=="cpp"):
        #g++ xyz.cpp
        subprocess.call(["g++","code/" + file_name],shell=True)    #this only compiles the code
        subprocess.call(["./a.out"],shell=True)          #this executes the compiled file.

my code file is there in the /code directory.

The directory structure is :

enter image description here

The conflict was resolved after I specified the removed the shell=True and specified the absolute path of the file using the os module.

Back to Top