class SimpleShell::Command
A command and it’s output
stdout and stderr are
Attributes
S[R]
err[R]
out[R]
Public Class Methods
new(shell)
click to toggle source
# File lib/simple_shell.rb, line 128 def initialize(shell) @shell = shell @base = shell.base @env = shell.env || {} @out = "" @err = "" @S = -1 end
Public Instance Methods
S?()
click to toggle source
cheap copy of $?
# File lib/simple_shell.rb, line 175 def S? @S end
execute(command, *args) { |stdin| ... }
click to toggle source
# File lib/simple_shell.rb, line 138 def execute(command, *args, &block) $stderr.puts("#{@env} #{command}, #{args}, #{@base}") if SimpleShell.noisy Open3.popen3(@env, "#{command}", *(args.collect { |a| "#{a}" }) , :chdir => @base) do |stdin, stdout, stderr, thread| threads = [] if @shell.stdout_handler threads << Thread.new(@shell.stdout_handler, stdout) do |handler, io| while(line = io.gets) handler.call(line) end end end if @shell.stderr_handler threads << Thread.new(@shell.stderr_handler, stderr) do |handler, io| while(line = io.gets) handler.call(line) end end end if block_given? yield stdin end stdin.close threads.collect(&:join) @out = @shell.stdout_handler ? nil : stdout.read.chomp @err = @shell.stderr_handler ? nil : stderr.read.chomp @S = thread.value rescue 0 end end
to_s()
click to toggle source
we just want to know the output of the command
# File lib/simple_shell.rb, line 180 def to_s @out end