Monday, September 5, 2022

[SOLVED] '.' is not recognized as an internal or external command, operable program or batch file

Issue

Trying to run a cpp program through shell, using exec command in nodejs, I wrote below exec command in node.js. (btw i am trying in windows)

exec(`g++ ${fileData.filepath} -o ${outPath} && cd ${outputPath} && ./${jobId}.exe,
   (error,stdout,stderr)=>{
                if(error){
                    reject({error,stderr})
                }
                if(stderr){
                    reject(stderr)
                }
                resolve(stdout)
            })

The Program is getting stored where it was expected to get stored in .exe format. There is one error which I am getting which is '.' is not recognized as an internal or external command, operable program or batch file. Help me fix this.


Solution

Just remove ./ from the exec command for executing the exe file, because ./ is used in linux, not in Windows ( When you are already in the directory containing the executable file ).

exec(`g++ ${fileData.filepath} -o ${outPath} && cd ${outputPath} && ${jobId}.exe`,
   (error,stdout,stderr) => {...})


Answered By - Abhay Bisht
Answer Checked By - Mary Flores (WPSolving Volunteer)