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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With