- if(!work_dir.empty())
- FS::chdir(work_dir);
- execvp(cargv.front(), const_cast<char *const *>(&cargv.front()));
- IO::print("Couldn't execute %s\n", argv.front());
- exit(1);
+ return cmd;
+}
+
+void ExternalTask::start()
+{
+ IO::File *devnull = 0;
+ IO::File *infile = 0;
+ IO::File *outfile = 0;
+
+ prepare();
+
+ process = new Process;
+
+ if(stdin_action==IGNORE || stdout_action==IGNORE || stderr_action==IGNORE)
+ {
+#ifdef _WIN32
+ devnull = new IO::File("nul", IO::M_RDWR);
+#else
+ devnull = new IO::File("/dev/null", IO::M_RDWR);
+#endif
+ if(stdin_action==IGNORE)
+ process->redirect_cin(*devnull);
+ if(stdout_action==IGNORE)
+ process->redirect_cout(*devnull);
+ if(stderr_action==IGNORE)
+ process->redirect_cerr(*devnull);
+ }
+
+ if(stdout_action==REDIRECT)
+ {
+ outfile = new IO::File((work_dir/stdout_file).str(), IO::M_WRITE);
+ process->redirect_cout(*outfile);
+ }
+
+ if(stdout_action==CAPTURE || stderr_action==CAPTURE)
+ {
+ capture_pipe = new IO::Pipe;
+ if(stdout_action==CAPTURE)
+ process->redirect_cout(*capture_pipe);
+ if(stderr_action==CAPTURE)
+ process->redirect_cerr(*capture_pipe);
+ }
+
+ if(stdin_action==REDIRECT)
+ {
+ infile = new IO::File((work_dir/stdin_file).str());
+ process->redirect_cin(*infile);