How to run an executable with spaces using std :: system on Windows without using C ++ 11?
I tried the seemingly obvious placement of quotation marks around the path with spaces, but in the console window that appears when the command starts, I get a message indicating that the full executable path is divided into spaces. For example, I tried the following:
int main()
{
int no_spaces_forward_rc = std::system("c:/IronPython2.7/ipy -c \"print 'no_spaces_forward'\"");
// no_spaces_forward_rc is 0 and "no_spaces_forward" is written to console window
int spaces_forward_rc = std::system("\"c:/Program Files (x86)/IronPython 2.7/ipy\" -c \"print 'spaces_forward'\"");
// spaces_forward_rc is 1, and "'c:/Program' is not recognized as an internal or external command, operable program or batch file." is written to console window
int no_spaces_backward_rc = std::system("c:\\IronPython2.7\\ipy -c \"print 'no_spaces_backward'\"");
// no_spaces_backward_rc is 0 and "no_spaces_backward" is written to console window
int spaces_backward_rc = std::system("\"c:\\Program Files (x86)\\IronPython 2.7\\ipy\" -c \"print 'spaces_backward'\"");
// spaces_backward_rc is 1, and "'c:\Program' is not recognized as an internal or external command, operable program or batch file." is written to console window
int no_spaces_double_backward_rc = std::system("c:\\\\IronPython2.7\\\\ipy -c \"print 'no_spaces_double_backward'\"");
// no_spaces_double_backward_rc is 0, and no_spaces_double_backward is written to console window
int spaces_double_backward_rc = std::system("\"c:\\\\Program Files (x86)\\\\IronPython 2.7\\\\ipy\" -c \"print 'spaces_double_backward'\"");
// spaces_double_backward_rc is 1, and "'c:\\Program' is not recognized as an internal or external command, operable program or batch file." is written to console window
int spaces_double_double_backward_rc = std::system("\\\"c:\\\\Program Files (x86)\\\\IronPython 2.7\\\\ipy\\\" -c \"print 'spaces_double_double_backward'\"");
// spaces_dobule_double_backward_rc is 1, and "'\"c:\\Program Files (x86)\\IronPython 2.7\\ipy\"' is not recognized as an internal or external command, operable program or batch file." is written to console window
return 0;
}
I checked that it works "c:\Program Files (x86)\IronPython 2.7\ipy" -c "print 'spaces_backward'"directly on the cmd command line, and I'm sure I have more than a typo. It drives me crazy - any help would be greatly appreciated!
(I am using Visual Studio 2012 and compiling using the Console subsystem if this helps.)