Greetings & Kind Regards
I am attempting to execute
cl.exe
via C++
system(...)
call w/ argument shown below:
"C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32019/bin/HostX64/x64/CL.exe" /JMC /permissive- /ifcOutput "x64/Debug" /GS /W3 /Zc:wchar_t /I"C:/Program Files (x86)/Visual Leak Detector/include" /ZI /Gm- /Od /sdl /Fd"x64/Debug/vc143.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++20 /FC /Fa"x64/Debug/" /EHsc /nologo /Fo"x64/Debug/" /Fp"x64/Debug/IOWIU.pch" /diagnostics:column /c main.cpp
The result is an error as shown below:
calling : system("C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32019/bin/HostX64/x64/CL.exe" /JMC /permissive- /ifcOutput "x64/Debug" /GS /W3 /Zc:wchar_t /I"C:/Program Files (x86)/Visual Leak Detector/include" /ZI /Gm- /Od /sdl /Fd"x64/Debug/vc143.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++20 /FC /Fa"x64/Debug/" /EHsc /nologo /Fo"x64/Debug/" /Fp"x64/Debug/IOWIU.pch" /diagnostics:column /c main.cpp)
'C:/Program' is not recognized as an internal or external command,
operable program or batch file.
return value is : 1
The same identical command run from the command line results in correct execution as shown below:
C:\Users\Bernard\source\repos\IOWIU>"C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32019/bin/HostX64/x64/CL.exe" /JMC /permissive- /ifcOutput "x64/Debug" /GS /W3 /Zc:wchar_t /I"C:/Program Files (x86)/Visual Leak Detector/include" /ZI /Gm- /Od /sdl /Fd"x64/Debug/vc143.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++20 /FC /Fa"x64/Debug/" /EHsc /nologo /Fo"x64/Debug/" /Fp"x64/Debug/IOWIU.pch" /diagnostics:column /c main.cpp
main.cpp
#include C:\Users\Bernard\source\repos\bpwSoftware\execution.MACROS.H
C:\Users\Bernard\source\repos\IOWIU>
Below is the relevant code:
string cl_path = "C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32019/bin/HostX64/x64/CL.exe";
string cl_options = "/JMC /permissive- /ifcOutput \"x64/Debug\" /GS /W3 /Zc:wchar_t /I\"C:/Program Files (x86)/Visual Leak Detector/include\" /ZI /Gm- /Od /sdl /Fd\"x64/Debug/vc143.pdb\" /Zc:inline /fp:precise /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_UNICODE\" /D \"UNICODE\" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++20 /FC /Fa\"x64/Debug/\" /EHsc /nologo /Fo\"x64/Debug/\" /Fp\"x64/Debug/IOWIU.pch\" /diagnostics:column /c";
string sspace = " ";
string sdbl_quotes = "\"";
auto left_paren = '(';
auto right_paren = ')';
auto system_arg = sdbl_quotes + cl_path + sdbl_quotes + sspace + cl_options + sspace + "main.cpp";
cout << "calling : system" << left_paren << system_arg << right_paren << endl;
auto result = system(system_arg.c_str());
cout << "return value is : " << result << endl;
The call to
system()
w/ the original
cl_path
works w/o error as
sdbl_quotes
is pre-post-pended to
cl_path
if only the 1st two options are passed so apparently the problem is w/ the 3rd option i.e. to wit
\"x64/Debug/\"
as passing it and only the 1st 2 and none of the remaining options results in the usual CMD error i.e.
'C:/Program' is not recognized as an internal or external command,
operable program or batch file.
The original option copied from project Property Pages please note the quotes are part of the option argument :
"x64\Debug\"
my converted form so as to form string type :
\"x64/Debug/\"
results in error I do not know how to resolve.
Below is a direct copy/paste of the screen output. As you can see the path to
cl.exe
is quoted which is precisely what the command processor sees and should see and still results in CMD error. You will also note the
/I
option argument is also quoted. Please note on the next output the quotes around the
/I
option argument are removed and the result is no CMD error reported only a compiler error which is expected demonstrating success in calling
cl.exe
.
__cplusplus 199711 _MSVC_LANG 202002
SYSTEM 2022-12-04 03:41:32.3135127
UTC 2022-12-04 03:41:32.3230103
TAI 2022-12-04 03:42:09.3644184
GPS 2022-12-04 03:41:50.3716110
FILE 2022-12-04 03:41:32.3781440
LOCAL 2022-12-03 22:41:32.3945656
calling : system("C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32019/bin/HostX64/x64/CL.exe" /permissive- /GS /W3 /Zc:wchar_t /I "C:\Users\Bernard\source\repos\bpwSoftware" /Gm- /Od /sdl /Zc:inline /fp:precise /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++20 /FC /EHsc /nologo /diagnostics:column /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE TEST.cpp)
'C:/Program' is not recognized as an internal or external command,
operable program or batch file.
return value is : 1
C:\Users\Bernard\source\repos\IOWIU\x64\Debug\IOWIU.exe (process 14484) exited with code 0.
Press any key to close this window . . .
__cplusplus 199711 _MSVC_LANG 202002
SYSTEM 2022-12-04 03:39:47.9385039
UTC 2022-12-04 03:39:47.9444312
TAI 2022-12-04 03:40:24.9793121
GPS 2022-12-04 03:40:05.9859770
FILE 2022-12-04 03:39:47.9899277
LOCAL 2022-12-03 22:39:48.0050586
calling : system("C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/MSVC/14.35.32019/bin/HostX64/x64/CL.exe" /permissive- /GS /W3 /Zc:wchar_t /I C:\Users\Bernard\source\repos\bpwSoftware /Gm- /Od /sdl /Zc:inline /fp:precise /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++20 /FC /EHsc /nologo /diagnostics:column /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE TEST.cpp)
TEST.cpp
C:\Users\Bernard\source\repos\IOWIU\TEST.cpp(1,9): error C2065: 'z': undeclared identifier
return value is : 2
C:\Users\Bernard\source\repos\IOWIU\x64\Debug\IOWIU.exe (process 14728) exited with code 0.
Press any key to close this window . . .
So in conclusion the problem all along has not been lack of quotes around
cl.exe
path as they have been present all along as these two above windows clearly demonstrate and has been stated repeatedly but rather the presence of quotes in option arguments as has also been previously stated and clearly demonstrated above.
May I suggest kind readers/advisors/helpers make effort to read/study/understand all text/comments etc. prior to advising/helping/assisting to avoid needless and troublesome repetition.
For further assistance please note the
/I
option is the 5th such i.e. to wit 1 , 2 , 3 , 4 , 5 ! Bingo! How hard was that. I assume counting is taught in Computer Science classes.
Thank You Kindly
What I have tried:
Read documentation re/ C++ system() , re/ CMD escape characters , re/ long path names which contain spaces.