Getting output of system() calls in Ruby

I’d like to expand & clarify chaos’s answer a bit. If you surround your command with backticks, then you don’t need to (explicitly) call system() at all. The backticks execute the command and return the output as a string. You can then assign the value to a variable like so: output = `ls` p output … Read more

.NET Process Monitor

WMI provides a way to track processes starting and terminating with the Win32_ProcessTrace classes. Best shown with an example. Start a new Console application, Project + Add Reference, select System.Management. Paste this code: using System; using System.Management; class Process { public static void Main() { ManagementEventWatcher startWatch = new ManagementEventWatcher( new WqlEventQuery(“SELECT * FROM Win32_ProcessStartTrace”)); … Read more

Get OS-level system information

You can get some limited memory information from the Runtime class. It really isn’t exactly what you are looking for, but I thought I would provide it for the sake of completeness. Here is a small example. Edit: You can also get disk usage information from the java.io.File class. The disk space usage stuff requires … Read more

How do I execute a command and get the output of the command within C++ using POSIX?

#include <cstdio> #include <iostream> #include <memory> #include <stdexcept> #include <string> #include <array> std::string exec(const char* cmd) { std::array<char, 128> buffer; std::string result; std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, “r”), pclose); if (!pipe) { throw std::runtime_error(“popen() failed!”); } while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { result += buffer.data(); } return result; } Pre-C++11 version: #include <iostream> #include <stdexcept> #include … Read more