File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,18 +112,30 @@ void os::init()
112112
113113int os::prog_exec (std::string exe, std::vector<std::string> &args)
114114{
115- // Create a vector with C pointers
116115 std::vector<const char *> pargs;
116+ #ifdef _WIN32
117+ // Escape any string with spaces in it:
118+ std::vector<std::string> esc_args;
117119 for (const auto &s : args)
120+ {
121+ if (s.find (' ' ) != s.npos )
122+ esc_args.push_back (" \" " + s + " \" " );
123+ else
124+ esc_args.push_back (s);
125+ }
126+ // Create a vector with C pointers
127+ for (const auto &s : esc_args)
118128 pargs.push_back (s.c_str ());
119129 pargs.push_back (nullptr );
120-
121- // Execute the program
122- #ifdef _WIN32
123130 // win32 has the "spawn" function that calls the program and waits
124131 // for termination:
125132 return _spawnv (_P_WAIT, exe.c_str (), (char **)pargs.data ());
126133#else
134+ // Create a vector with C pointers
135+ for (const auto &s : args)
136+ pargs.push_back (s.c_str ());
137+ pargs.push_back (nullptr );
138+
127139 // We reimplement "system" to allow passing arguments without escaping:
128140
129141 // Ignore INT and QUIT signals in the parent process:
You can’t perform that action at this time.
0 commit comments