[SOLVED] Error in using system() for compilation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

[SOLVED] Error in using system() for compilation

I am trying to invoke the g++ compiler to generate assembly and preprocessor files for a C++ source code using system(). I have the compiler located in a different drive, and the folder name contains spaces, so I decided to use the following command : "F:\ Files\MinGW GCC 7.2\MinGW\bin\g++.exe" -std=c++17 -S -save-temps "H:\All C++ Files\Rough\Main.cpp" However, when I run the program, I get the following error : " 'F:\' is not recognized as an internal or external command, operable program or batch file. " The command, however, works just as it should when pasted inside cmd. Why does system consider only the F:\ as the specified command? Why does it ignore the rest of the statement? Here is the code being used for the same. https://code.sololearn.com/cbki7Lg0Drb7/#cpp

9th Aug 2018, 1:37 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
10 Answers
+ 1
Hi Kinshuk Vasisht, maybe try with ShellExecute or ShellExecuteEx function, it supports parameters/arguments: https://docs.microsoft.com/en-us/windows/desktop/shell/launch https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/ns-shellapi-_shellexecuteinfoa Best of luck : )
10th Aug 2018, 4:35 AM
Ipang
+ 4
Kinshuk Vasisht Thanks for sharing : )
11th Aug 2018, 5:44 AM
Ipang
+ 3
Danik 45 Don't worry. You can learn the basics from the C++ Tutorial here. But next time, try posting such questions in your feed.
10th Aug 2018, 12:10 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
Hi Kinshuk, Why are you inserting a space between 'F:\' and 'File\' ? Does it really exists?
9th Aug 2018, 3:09 PM
Mark
+ 2
Ipang Thank you very much for the suggestion. I'll try it and let you know if it worked for me... Edit : ShellExecute worked like a charm. Thank you very much!
10th Aug 2018, 12:09 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 2
Kinshuk Vasisht share code link please? so others can learn also : )
10th Aug 2018, 3:42 PM
Ipang
+ 1
Hi Kinshuk Vasisht, can you provided more details about the environment you are compiling/executing your code? can you provide a minimum piece of code in which you can observe the problem? I will try to reproduce the error in my machine. Than I will be able to help you more.
9th Aug 2018, 7:10 PM
Mark
+ 1
Mark I am using a Windows 7 64 bit PC, and am compiling my code using GCC v7.2, which I have inside a MinGW Package. The code can be found attached with the question itself as a Code Playground link.
10th Aug 2018, 1:13 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
Ipang Here is the final code, which also mentions some details about the parameter requirements : https://code.sololearn.com/cl7h777e9CT1/?ref=app
11th Aug 2018, 5:37 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
0
Mark Unfortunately, the space does exist. I mistyped the name during creation.
9th Aug 2018, 3:21 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar