/tutorial/io/redirection_example.e

http://github.com/tybor/Liberty · Specman e · 29 lines · 23 code · 3 blank · 3 comment · 1 complexity · 86f7bdc20c51fa687976b56d2a8559f1 MD5 · raw file

  1. class REDIRECTION_EXAMPLE
  2. --
  3. -- Shows how to redirect `std_input_stream', `std_output_stream' and `std_error_stream'.
  4. --
  5. create {ANY}
  6. make
  7. feature {}
  8. make
  9. local
  10. log_name: STRING; log_file: TEXT_FILE_WRITE
  11. do
  12. log_name := "redirection_example.log"
  13. io.put_string("Output redirected on %"" + log_name + "%".%N")
  14. create log_file.connect_to(log_name)
  15. if log_file.is_connected then
  16. standard_streams.set_std_output(log_file)
  17. standard_streams.std_output.put_string("This is not on the screen!%N")
  18. log_file.put_string("This is not on the screen!%N")
  19. standard_streams.restore_std_output
  20. log_file.disconnect
  21. standard_streams.std_output.put_string("Do not forget to remove the %"" + log_name + "%" file.%N")
  22. else
  23. std_output.put_string("Cannot write %"" + log_name + "%" in the current working directory.%N")
  24. end
  25. end
  26. end -- class REDIRECTION_EXAMPLE