| Class | Uttk::Strategies::CmdBase |
| In: |
lib/uttk/strategies/CmdBase.rb
|
| Parent: | IOBased |
| my_exit | [R] | Attributes |
| my_status | [R] | Attributes |
| pid | [R] | Attributes |
Constructor
# File lib/uttk/strategies/CmdBase.rb, line 18 def initialize ( *a, &b ) super @my_exit, @pid, @my_status = nil, nil, nil end
# File lib/uttk/strategies/CmdBase.rb, line 68 def abort_hook unless @pid.nil? begin Process.kill('-KILL', -@pid) waitpid rescue Errno::ESRCH @log.already_killed = @pid end end @my_exit = 134 # Common status returned by sh on a SIGABRT super end
# File lib/uttk/strategies/CmdBase.rb, line 92 def mk_command cmd = @command.to_s.dup cmd += ' %a' if cmd !~ /%a/ and @args cmd.gsub!(/%a/, @args.to_s) if @args if cmd =~ /%i/ and @input and @input.my cmd.gsub!(/%i/, @input.my.to_s) @input_in_args = true else @input_in_args = false end cmd end
Methods
# File lib/uttk/strategies/CmdBase.rb, line 28 def run_impl begin cmd = mk_command cmd.gsub!("\n", ' ') @log[:running] = cmd @pid = Kernel.fork do unless @input.nil? or @input_in_args STDIN.reopen(@input.my.open('r')) end STDOUT.reopen(@output.my.open('w')) unless @output.nil? STDERR.reopen(@error.my.open('w')) unless @error.nil? Dir.chdir(@dir.to_s) if @dir begin son_hook exec(cmd) rescue Exception => ex @log.exception_raised_during_exec = ex exit! 127 end end father_hook waitpid fail('exception raised during exec') if @my_exit == 127 end end