MCPcopy Create free account
hub / github.com/columbia/egalito / runGeneratedFile

Method runGeneratedFile

app/shell2/code.cpp:310–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

308}
309
310bool FullCommandList::runGeneratedFile(const char *file, ShellState &state,
311 ArgumentValueList &args) const {
312
313 auto pid = fork();
314 if(!pid) {
315 unsigned long file0 = (file ? 1 : 0);
316 unsigned long count = args.getIndexedCount();
317 char **argv = static_cast<char **>(
318 malloc((file0 + count + 1) * sizeof(*argv)));
319 unsigned long argc = 0;
320 if(file0) argv[argc++] = const_cast<char *>(file);
321 for(unsigned long i = 0; i < count; i ++) {
322 argv[argc++] = strdup(args.getIndexed(i).getString().c_str());
323 }
324 argv[argc] = nullptr;
325#if 0
326 for(unsigned long i = 0; argv[i]; i ++) {
327 std::cout << "\"" << argv[i] << "\",";
328 }
329 std::cout << std::endl;
330#endif
331 execvp(argv[0], argv);
332 std::exit(1);
333 }
334 else {
335 int status = 0;
336 waitpid(pid, &status, 0);
337
338 bool normal = (WIFEXITED(status) && WEXITSTATUS(status) == 0);
339 return normal;
340 }
341}

Callers

nothing calls this directly

Calls 2

getIndexedCountMethod · 0.80
getStringMethod · 0.80

Tested by

no test coverage detected