1 #ifndef EXTERNALTASK_H_
2 #define EXTERNALTASK_H_
6 #include <msp/fs/path.h>
7 #include <msp/io/pipe.h>
11 Runs an external command. A zero exit status is translated to a SUCCESS status
12 for the task, and anything else is treated as an error. Output can optionally
15 class ExternalTask: public Task
25 typedef std::vector<std::string> Arguments;
29 Msp::FS::Path work_dir;
32 Destination stdout_dest;
33 Destination stderr_dest;
34 Msp::IO::Pipe *capture_pipe;
38 /** Creates an ExternalTask with an argument array and an optional working
39 directory. The first element of the argument array should be the command
40 name. If the working directory is not specified, no chdir is done. */
41 ExternalTask(const Arguments &, const Msp::FS::Path & = Msp::FS::Path());
43 virtual ~ExternalTask();
45 virtual std::string get_command() const;
47 virtual Status check();
53 void set_stdout(Destination);
54 void set_stderr(Destination);
55 const std::string &get_output() const { return output; }
57 /** Executes a command and captures its output. Stderr is ignored, but if
58 the command exits with a nonzero status, an exception is thrown. */
59 static std::string run_and_capture_output(const Arguments &, const Msp::FS::Path & = Msp::FS::Path());