Difference between $stdout and STDOUT in Ruby

$stdout is a global variable that represents the current standard output. STDOUT is a constant representing standard output and is typically the default value of $stdout. With STDOUT being a constant, you shouldn’t re-define it, however, you can re-define $stdout without errors/warnings (re-defining STDOUT will raise a warning). for example, you can do: $stdout = … Read more

Redirect process output C#

Use RedirectStandardOutput. Sample from MSDN: // Start the child process. Process p = new Process(); // Redirect the output stream of the child process. p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = “Write500Lines.exe”; p.Start(); // Do not wait for the child process to exit before // reading to the end of its redirected stream. // … Read more

How to execute system commands (linux/bsd) using Java

Your way isn’t far off from what I’d probably do: Runtime r = Runtime.getRuntime(); Process p = r.exec(“uname -a”); p.waitFor(); BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = “”; while ((line = b.readLine()) != null) { System.out.println(line); } b.close(); Handle whichever exceptions you care to, of course.