Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

$stdout ruby override

#!/usr/bin/ruby

logfile = "/tmp/testruby.log"

@original_stdout = $stderr.dup
@original_stderr = $stderr.dup
$stdout.reopen(logfile, "w")
$stdout.sync = true
$stderr.reopen($stdout)


def restore_stdout
  $stdout.reopen(@original_stdout)
  $stderr.reopen(@original_stderr)
end

def fail_exit(msg)
  puts "- #{msg}" # to the logfile
  restore_stdout
  $stderr.puts "+ #{msg}" # to standard error
  exit!
end

def success_exit(msg)
  puts "- #{msg}" # to the logfile
  restore_stdout  
  $stdout.puts "+ #{msg}" # to standard output
  exit
end

puts "This message goes to the file"

success_exit "A successful exit message"
Comment

PREVIOUS NEXT
Code Example
Ruby :: how to add two variables into a hash ruby 
Ruby :: refactor duplicate tests rspec 
Ruby :: self referencing association in ruby on rails 
Ruby :: rails db:drop not working 
Ruby :: ruby get classname 
Ruby :: rails spreadsheet email attachment 
Ruby :: singning in using username rails 
Ruby :: time loop start with non zero in ruby 
Ruby :: call api in ruby 
Ruby :: ruby decode base64 
Ruby :: model with array rails 
Ruby :: rails revert migration 
R :: paste no space r 
R :: dplyr colnames r 
R :: glyph in r 
R :: rstudio could not find function ggplot 
R :: r combine strings 
R :: chi square critical value in r 
R :: convert a row to a column in r 
R :: write text r 
R :: r type of object 
R :: mutate in r if else 
R :: how to wait for a key press in R 
R :: r mode 
R :: run regression for certain groups in r 
R :: R currency ggplot axis 
R :: list variables r 
R :: add comma every 3 digits in r 
R :: r studio 
Rust :: rust dictionary 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =