Module: Maxima::Helper
- Defined in:
- lib/maxima/helper.rb
Class Method Summary collapse
Class Method Details
.spawn_silenced_shell_process(shell_command) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/maxima/helper.rb', line 41 def self.spawn_silenced_shell_process(shell_command) stfu do rout, wout = IO.pipe result = nil begin pid = Process.spawn(shell_command, out: wout) _, _ = Process.wait2(pid) ensure wout.close if $interrupted rout.close throw :interrupted else result = rout.readlines.join("\n") rout.close end end result end end |
.stfu ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/maxima/helper.rb', line 10 def self.stfu result = nil begin orig_stderr = $stderr.clone orig_stdout = $stdout.clone $stderr.reopen File.new('/dev/null', 'w') $stdout.reopen File.new('/dev/null', 'w') result = yield rescue Exception => e if $interrupted throw :interrupted else $stdout.reopen orig_stdout $stderr.reopen orig_stderr raise e end ensure if $interrupted throw :interrupted else $stdout.reopen orig_stdout $stderr.reopen orig_stderr end end if $interrupted throw :interrupted else result end end |