class Session::Sh
Constants
- DEFAULT_PROG
- ECHO
Attributes
exit_status[R]
exitstatus[R]
status[R]
Public Instance Methods
clear()
click to toggle source
# File lib/session.rb, line 446 def clear stdin.puts "#{ ECHO } __clear__ 1>&2" stdin.puts "#{ ECHO } __clear__" stdin.flush while((line = stderr.gets) and line !~ %r/__clear__/o); end while((line = stdout.gets) and line !~ %r/__clear__/o); end self end
execute(command, redirects = {}, &block)
click to toggle source
Calls superclass method
Session::AbstractSession#execute
# File lib/session.rb, line 509 def execute(command, redirects = {}, &block) # setup redirect on stdin rin = redirects[:i] || redirects[:in] || redirects[:stdin] || redirects['stdin'] || redirects['i'] || redirects['in'] || redirects[0] || redirects['0'] if rin tmp = begin Tempfile::new rand.to_s rescue Tempfile::new rand.to_s end begin tmp.write( if rin.respond_to? 'read' rin.read elsif rin.respond_to? 'to_s' rin.to_s else rin end ) tmp.flush command = "{ #{ command } ;} < #{ tmp.path }" #puts command super(command, redirects, &block) ensure tmp.close! if tmp end else super end end
get_status()
click to toggle source
# File lib/session.rb, line 466 def get_status @status = get_var '__exit_status__' unless @status =~ /^\s*\d+\s*$/o raise ExecutionError, "could not determine exit status from <#{ @status.inspect }>" end @status = Integer @status end
get_var(name)
click to toggle source
# File lib/session.rb, line 478 def get_var name stdin.puts "#{ ECHO } \"#{ name }=${#{ name }}\"" stdin.flush var = nil while((line = stdout.gets)) m = %r/#{ name }\s*=\s*(.*)/.match line if m var = m[1] raise ExecutionError, "could not determine <#{ name }> from <#{ line.inspect }>" unless var break end end var end
path()
click to toggle source
# File lib/session.rb, line 494 def path var = get_var 'PATH' var.strip.split %r/:/o end
path=(arg)
click to toggle source
# File lib/session.rb, line 498 def path= arg case arg when Array arg = arg.join ':' else arg = arg.to_s.strip end set_var 'PATH', "'#{ arg }'" self.path end
send_command(cmd)
click to toggle source
# File lib/session.rb, line 454 def send_command cmd stdin.printf "%s '%s' 1>&2\n", ECHO, cmd.begin_err stdin.printf "%s '%s' \n", ECHO, cmd.begin_out stdin.printf "%s\n", cmd.cmd stdin.printf "export __exit_status__=$?\n" stdin.printf "%s '%s' 1>&2\n", ECHO, cmd.end_err stdin.printf "%s '%s' \n", ECHO, cmd.end_out stdin.flush end
set_var(name, value)
click to toggle source
# File lib/session.rb, line 474 def set_var name, value stdin.puts "export #{ name }=#{ value }" stdin.flush end