+
+void ExternalTask::set_stdin(const FS::Path &f)
+{
+ stdin_action = REDIRECT;
+ stdin_file = f;
+}
+
+void ExternalTask::set_stdout(StreamAction a)
+{
+ if(a==REDIRECT)
+ throw invalid_argument("ExternalTask::set_stdout");
+ stdout_action = a;
+}
+
+void ExternalTask::set_stdout(const FS::Path &f)
+{
+ stdout_action = REDIRECT;
+ stdout_file = f;
+}
+
+void ExternalTask::set_stderr(StreamAction a)
+{
+ if(a==REDIRECT)
+ throw invalid_argument("ExternalTask::set_stdout");
+ stderr_action = a;
+}
+
+string ExternalTask::run_and_capture_output(const Arguments &argv, const FS::Path &wd, bool capture_stderr)
+{
+ ExternalTask task(argv, wd);
+ task.stdin_action = IGNORE;
+ task.set_stdout(CAPTURE);
+ task.set_stderr(capture_stderr ? CAPTURE : IGNORE);
+ task.start();
+ if(task.wait()!=SUCCESS)
+ throw runtime_error(format("%s failed", argv.front()));
+ return task.get_output();
+}