How to write CSV output to stdout?

sys.stdout is a file object corresponding to the program’s standard output. You can use its write() method. Note that it’s probably not necessary to use the with statement, because stdout does not have to be opened or closed. So, if you need to create a csv.writer object, you can just say: import sys spamwriter = … Read more

How to replicate tee behavior in Python when using subprocess?

I see that this is a rather old post but just in case someone is still searching for a way to do this: proc = subprocess.Popen([“ping”, “localhost”], stdout=subprocess.PIPE, stderr=subprocess.PIPE) with open(“logfile.txt”, “w”) as log_file: while proc.poll() is None: line = proc.stderr.readline() if line: print “err: ” + line.strip() log_file.write(line) line = proc.stdout.readline() if line: print … Read more

Continuously read from STDOUT of external process in Ruby

I’ve had some success in solving this problem of mine. Here are the details, with some explanations, in case anyone having a similar problem finds this page. But if you don’t care for details, here’s the short answer: Use PTY.spawn in the following manner (with your own command of course): require ‘pty’ cmd = “blender … Read more

How to get Rails.logger printing to the console/stdout when running rspec?

For Rails 4.x the log level is configured a bit different than in Rails 3.x Add this to config/environment/test.rb # Enable stdout logger config.logger = Logger.new(STDOUT) # Set log level config.log_level = :ERROR The logger level is set on the logger instance from config.log_level at: https://github.com/rails/rails/blob/v4.2.4/railties/lib/rails/application/bootstrap.rb#L70 Environment variable As a bonus, you can allow overwriting … Read more

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