Module: TezosClient::Tools::SystemCall

Defined in:
lib/tezos_client/tools/system_call.rb

Class Method Summary collapse

Class Method Details

.execute(cmd) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tezos_client/tools/system_call.rb', line 6

def self.execute(cmd)
  Open3.popen3(*cmd) do |_stdin, stdout, stderr, wait_thr|
    err = stderr.read
    status = wait_thr.value.exitstatus

    if status != 0
      raise ::TezosClient::SysCallError, "command '#{cmd}' existed with status #{status}: #{err}"
    end

    output = stdout.read

    if block_given?
      yield(output)
    else
      output
    end
  end
end