{
stderr_dest = d;
}
+
+string ExternalTask::run_and_capture_output(const Arguments &argv, const FS::Path &wd)
+{
+ ExternalTask task(argv, wd);
+ task.set_stdout(CAPTURE);
+ task.set_stderr(IGNORE);
+ task.start();
+ Task::Status status;
+ while((status=task.check())==RUNNING) ;
+ if(status!=SUCCESS)
+ throw runtime_error(format("%s failed", argv.front()));
+ return task.get_output();
+}
void set_stdout(Destination);
void set_stderr(Destination);
const std::string &get_output() const { return output; }
+
+ /** Executes a command and captures its output. Stderr is ignored, but if
+ the command exits with a nonzero status, an exception is thrown. */
+ static std::string run_and_capture_output(const Arguments &, const Msp::FS::Path & = Msp::FS::Path());
};
#endif
argv.push_back(executable->get_path().str());
argv.push_back("-dumpversion");
builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
- ExternalTask task(argv);
- task.set_stdout(ExternalTask::CAPTURE);
- task.set_stderr(ExternalTask::IGNORE);
- task.start();
- Task::Status status;
- while((status=task.check())==Task::RUNNING) ;
- if(status==Task::SUCCESS)
+ try
{
- string cxx_ver = strip(task.get_output());
+ string cxx_ver = strip(ExternalTask::run_and_capture_output(argv));
FS::Path cxx_path = FS::Path("/usr/include/c++")/cxx_ver;
if(FS::is_dir(cxx_path))
{
system_path.push_back(cxx_path);
}
}
+ catch(const runtime_error &)
+ { }
}
Target *GnuCxxCompiler::create_source(const Component &comp, const FS::Path &path) const
builder.get_logger().log("auxcommands", format("Running %s", join(argv.begin(), argv.end())));
- ExternalTask task(argv);
- task.set_stdout(ExternalTask::CAPTURE);
- task.set_stderr(ExternalTask::IGNORE);
- task.start();
- Task::Status status;
- while((status=task.check())==Task::RUNNING)
- Time::sleep(10*Time::msec);
- if(status==Task::ERROR)
- throw runtime_error(format("pkg-config for package %s failed", pkg));
-
- return task.get_output();
+ return ExternalTask::run_and_capture_output(argv);
}
FS::Path PackageManager::get_package_location(const string &name)