Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue using system() on Windows [duplicate]

Tags:

c++

quotes

exe

I have a C++ program that is trying to call an executable with two parameters. The code works fine on Mac, but I have some issues on Windows. I'm confident that the issue is related to spaces in the parameters because when I use a path with no spaces it works just fine.

Furthermore, I print out what I'm sending into system() and then I run that printout on the command line and it works just fine which is trifling.

I make a call like this: ret = system(cmd.c_str());

And if I do: cout << cmd << endl; I'll get something like this:

"C:\Program Files (x86)\MyProgram\some_executable.exe" "C:\Users\me\Desktop\files"

I'm not sure why the quotes aren't helping, I am including quotes around the paths in the system() call. The printout of cmd is exactly what I'm trying to run but it doesn't work. However, if that path had no spaces in it, it would execute just fine.

Any suggestions on passing parameters with spaces to a system() call?

like image 363
roundtheworld Avatar asked Jun 10 '26 01:06

roundtheworld


1 Answers

After more research, the issue is related to Windows being stupid. The system call removes the first and last quote, so I had to wrap the whole thing in another set of quotes...I found my solution here: C++ system() not working when there are spaces in two different parameters

like image 180
roundtheworld Avatar answered Jun 11 '26 14:06

roundtheworld