Skip to content
Snippets Groups Projects
Select Git revision
  • ff7ddd4b0297e545f12f8182ef92c4ac8d103afb
  • master default protected
2 results

main.cpp

  • consoir's avatar
    Simon Consoir authored
    ff7ddd4b
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    main.cpp 747 B
    #include "crow.h"
    #include <cstdlib>
    #include <sstream>
    #include <fstream>
    
    int main() {
        crow::SimpleApp app;
    
        CROW_ROUTE(app, "/execute").methods(crow::HTTPMethod::Post)
        ([](const crow::request& req, crow::response& res) {
            std::string command = req.body;
    
            std::string full_command = command + " 2>&1 | tee output.txt";
            int result = std::system(full_command.c_str());
    
            // Read the output from the file
            std::ifstream output_file("output.txt");
            std::stringstream output_buffer;
            output_buffer << output_file.rdbuf();
            std::string output = output_buffer.str();
    
            res.write("Done");
            res.end();
        });
    
        app.port(10001).multithreaded().run();
    
        return 0;
    }