@@ -135,13 +135,36 @@ void exec(const std::string& prog, const std::string& args, const std::string& d
135
135
#include < fcntl.h>
136
136
#include < spawn.h>
137
137
#include < sys/wait.h>
138
- #include < boost/program_options.hpp>
138
+ #include < boost/tokenizer.hpp>
139
+ #include < boost/shared_array.hpp>
139
140
#include < vector>
140
141
141
142
extern char **environ;
142
143
143
144
namespace plexus {
144
145
146
+ boost::shared_array<char *>make_arguments (const std::string& exe,const std::string& args)
147
+ {
148
+ auto holder = std::make_shared<std::vector<std::string>>();
149
+ holder->push_back (boost::replace_all_copy (exe," " ," \\ " ));
150
+
151
+ boost::tokenizer<boost::escaped_list_separator<char >>tokenizer (args.begin (), args.end (), boost::escaped_list_separator<char >(" \\ " ," \t " ," '\" " ));
152
+ auto iter = tokenizer.begin ();
153
+ while (iter != tokenizer.end ())
154
+ {
155
+ if (!iter->empty ())
156
+ holder->push_back (iter->c_str ());
157
+ ++iter;
158
+ }
159
+
160
+ boost::shared_array<char *>array (new char *[holder->size () +1 ], [holder](char ** ptr) {delete[] ptr; });
161
+ for (size_t i =0 ; i < holder->size (); ++i)
162
+ array[i] = holder->at (i).data ();
163
+ array[holder->size ()] =0 ;
164
+
165
+ return array;
166
+ }
167
+
145
168
void exec (const std::string& prog,const std::string& args,const std::string& dir,const std::string& log,bool wait)noexcept (false )
146
169
{
147
170
_dbg_ <<" execute: cmd=\" " << prog <<" \" args=\" " << args <<" \" pwd=\" " << dir <<" \" log=\" " << log <<" \" " ;
@@ -160,14 +183,7 @@ void exec(const std::string& prog, const std::string& args, const std::string& d
160
183
});
161
184
});
162
185
163
- auto exe =boost::replace_all_copy (prog," " ," \\ " );
164
- auto arguments =boost::program_options::split_unix (args);
165
-
166
- std::vector<char *> argv;
167
- argv.push_back (exe.data ());
168
- for (auto & arg : arguments)
169
- argv.push_back (arg.data ());
170
- argv.push_back (0 );
186
+ auto argv =make_arguments (prog, args);
171
187
172
188
posix_spawn_file_actions_t action;
173
189
int status =posix_spawn_file_actions_init (&action);
@@ -219,7 +235,7 @@ void exec(const std::string& prog, const std::string& args, const std::string& d
219
235
throw std::runtime_error (utils::format (" posix_spawnattr_setflags: error=%d" , status));
220
236
221
237
pid_t pid;
222
- status =posix_spawnp (&pid,exe. data () , &action, &attr, argv.data (), environ);
238
+ status =posix_spawnp (&pid,argv[ 0 ] , &action, &attr, argv.get (), environ);
223
239
if (status)
224
240
throw std::runtime_error (utils::format (" posix_spawn: error=%d" , status));
225
241