def system(cmd_str, args=[], opts={})
      unless EventMachine.reactor_running?
        raise "has to prepare EventMachine context"
      end

      cmd = quote_args(cmd_str, args, (opts[:quote_char] || '\''))

      capture_io = opts[:io] || StringIO.new
      stdin_buf = opts[:stdin_input]
      
      evmsg = {:cmd => cmd}
      wait_q = ::Queue.new
      if opts[:timeout] && opts[:timeout].to_f > 0.0
        EventMachine.add_timer(opts[:timeout].to_f) {
          wait_q.enq(RuntimeError.new("timeout child process wait: #{opts[:timeout].to_f} sec(s)"))
        }
        evmsg[:timeout] = opts[:timeout].to_f        
      end
      popenobj = EventMachine.popen(cmd, EmSystemCb, capture_io, stdin_buf, proc { |exit_stat|
                                      wait_q.enq(exit_stat)
                                    })
      pid = EventMachine.get_subprocess_pid(popenobj.signature)
      evmsg[:pid] = pid
      if self.respond_to? :logger
        logger.debug("Exec command (pid=#{pid}): #{cmd}")
      end

      stat = wait_q.deq
      evmsg = {}
      
      case stat
      when Process::Status
        evmsg[:exit_code] = stat.exitstatus
        if stat.exited? && stat.exitstatus == 0
        else
          raise "Unexpected status from child: #{stat}"
        end
      when Exception
        raise stat
      else
        raise "Unknown signal from child: #{stat}"
      end
      
    end
def system(cmd_str, args=[], opts={})
      unless EventMachine.reactor_running?
        raise "has to prepare EventMachine context"
      end

      cmd = quote_args(cmd_str, args, (opts[:quote_char] || '\''))

      capture_io = opts[:io] || StringIO.new
      stdin_buf = opts[:stdin_input]
      
      evmsg = {:cmd => cmd}
      wait_q = ::Queue.new
      if opts[:timeout] && opts[:timeout].to_f > 0.0
        EventMachine.add_timer(opts[:timeout].to_f) {
          wait_q.enq(RuntimeError.new("timeout child process wait: #{opts[:timeout].to_f} sec(s)"))
        }
        evmsg[:timeout] = opts[:timeout].to_f        
      end
      popenobj = EventMachine.popen(cmd, EmSystemCb, capture_io, stdin_buf, proc { |exit_stat|
                                      wait_q.enq(exit_stat)
                                    })
      pid = EventMachine.get_subprocess_pid(popenobj.signature)
      evmsg[:pid] = pid
      if self.respond_to? :logger
        logger.debug("Exec command (pid=#{pid}): #{cmd}")
      end

      stat = wait_q.deq
      evmsg = {}
      
      case stat
      when Process::Status
        evmsg[:exit_code] = stat.exitstatus
        if stat.exited? && stat.exitstatus == 0
        else
          raise "Unexpected status from child: #{stat}"
        end
      when Exception
        raise stat
      else
        raise "Unknown signal from child: #{stat}"
      end
      
    end
system('/bin/ls')
 second arg gives
 system('/bin/ls %s', ['/home'])