Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
map_file_mangling
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <iostream> #include <string> FILE* PipeOpen(const char* command, const char* type) { #if defined (_MSC_VER) return _popen(command, type); #else return popen(command, type); #endif } int PipeClose(FILE* stream) { #if defined (_MSC_VER) return _pclose(stream); #else return pclose(stream); #endif } std::string RunCommand(const std::string& cmd, bool verbose = false) { FILE* pipe(PipeOpen(cmd.c_str(), "r")); char buffer[1024]; std::string output = ""; while (!feof(pipe)) { if (fgets(buffer, 1024, pipe) != NULL) output += buffer; } PipeClose(pipe); if (verbose) std::cout << "---------\n" << "RunCommand: " << cmd << '\n' << "---------\n" << std::endl; return output; } int main() { std::cout << RunCommand("cd.. & dir & type cl.bat", true) << std::endl; std::cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
Two-phase sample with Visual C++ 2015
No UD
Copy vs Reference
fun
Regex pipe and tabs c++
Number of paths in matrix
wrong up
infix to postfix v 3.0 with improved eval()
C++ string format
cross-platform sleep function