Sha256: 917b2dfbe05b882c81b2fa69f6da4dabb7cb5d141cee90f1cf15ccb2f48d2c22
Contents?: true
Size: 1.92 KB
Versions: 50
Compression:
Stored size: 1.92 KB
Contents
#include <iostream> #include "fcgio.h" using namespace std; int mmain(); #include <array> int main(void) { // Backup the stdio streambufs streambuf * cin_streambuf = cin.rdbuf(); streambuf * cout_streambuf = cout.rdbuf(); streambuf * cerr_streambuf = cerr.rdbuf(); FCGX_Request request; FCGX_Init(); FCGX_InitRequest(&request, 0, 0); while (FCGX_Accept_r(&request) == 0) { fcgi_streambuf cin_fcgi_streambuf(request.in); fcgi_streambuf cout_fcgi_streambuf(request.out); fcgi_streambuf cerr_fcgi_streambuf(request.err); cin.rdbuf(&cin_fcgi_streambuf); cout.rdbuf(&cout_fcgi_streambuf); cerr.rdbuf(&cerr_fcgi_streambuf); cout << "Content-type: text/html\r\n" << "\r\n" << "<html>\n" << " <head>\n" << " <title>Hello, World!</title>\n" << " </head>\n" << " <body>\n" << " <h1>Hello, World!</h1>\n" << " </body>\n" << "</html>\n"; system("echo 5 > /root/six"); mmain(); // system("echo 6"); // Note: the fcgi_streambuf destructor will auto flush } // restore stdio streambufs cin.rdbuf(cin_streambuf); cout.rdbuf(cout_streambuf); cerr.rdbuf(cerr_streambuf); return 0; } int mmain() { std::string command("ls * 2>&1"); std::array<char, 4096> buffer; std::string result; std::cout << "Opening reading pipe" << std::endl; FILE* pipe = popen(command.c_str(), "r"); if (!pipe) { std::cerr << "Couldn't start command." << std::endl; return 0; } while (fgets(buffer.data(), 128, pipe) != NULL) { //std::cout << "Reading..." << std::endl; result += buffer.data(); } auto returnCode = pclose(pipe); std::cout << result << std::endl; std::cout << returnCode << std::endl; return 0; }
Version data entries
50 entries across 49 versions & 6 rubygems