Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <chrono>
- #include <iostream>
- #include <fstream>
- #include <mutex>
- #include <vector>
- #include <memory>
- using namespace std;
- static mutex theLock;
- string exec(const char* cmd) {
- array<char, 1024> buffer;
- string result;
- shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
- if (!pipe) {
- throw runtime_error("popen() failed!");
- }
- while (!feof(pipe.get())) {
- if (fgets(buffer.data(), 1024, pipe.get()) != NULL) {
- result += buffer.data();
- }
- }
- return result;
- }
- void produce(const string &path) {
- string output = exec(("cd " + path + " && git pull 2>&1").c_str());
- if(output != "Already up-to-date.\n") {
- cout << (output + '\n');
- }
- }
- int main() {
- ifstream repos;
- repos.open("repos");
- if(!repos.is_open()) {
- cout << "Couldn't open repos file.";
- return -1;
- }
- string line;
- vector<string> lines;
- while(getline(repos, line)) {
- if(line != "") {
- lines.push_back(line);
- }
- }
- repos.close();
- #pragma omp parallel for
- for(size_t i = 0; i < lines.size(); i++) {
- produce(lines[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment