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

multiprocessing: How can I ʀᴇʟɪᴀʙʟʏ redirect stdout from a child process?

The solution you suggest is a good one: create your processes manually such that you have explicit access to their stdout/stderr file handles. You can then create a socket to communicate with the sub-process and use multiprocessing.connection over that socket (multiprocessing.Pipe creates the same type of connection object, so this should give you all the … Read more

How can I redirect stdout and stderr without polluting PowerShell error output

Your symptom implies that $ErrorActionPreference=”Stop” is in effect at the time function Test-Validation executes. (Temporarily) set it to ‘Continue’ to fix your problem – which in future versions will hopefully no longer required (see below). The reason for the observed behavior is that, in Windows PowerShell and up to PowerShell (Coe) 7.1, using an error-stream … Read more

Make cURL output STDERR to file (or string)

You are making couple mistakes in your example: 1) you have to call curl_exec() prior to reading from the “verbose log”, because curl_setopt() doesn’t perform any action, so nothing can be logged prior to the curl_exec(). 2) you are opening $curl_log = fopen(“curl.txt”, ‘w’); only for write, so nothing could be read, even after you … Read more

“subprocess.Popen” – checking for success and errors

Do you need to do anything with the output of the process? The check_call method might be useful here. See the python docs here: https://docs.python.org/2/library/subprocess.html#subprocess.check_call You can then use this as follows: try: subprocess.check_call(command) except subprocess.CalledProcessError: # There was an error – command exited with non-zero code However, this relies on command returning an exit … Read more

How do I temporarily redirect stderr in Ruby?

In Ruby, $stderr refers to the output stream that is currently used as stderr, whereas STDERR is the default stderr stream. It is easy to temporarily assign a different output stream to $stderr. require “stringio” def capture_stderr # The output stream must be an IO-like object. In this case we capture it in # an … Read more