Class: Lastpass::Utils Private
- Inherits:
-
Object
- Object
- Lastpass::Utils
- Defined in:
- lib/lastpass-api/utils.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Internal utility class
Class Method Summary collapse
-
.cmd(command, output: false) ⇒ String
private
Run a command.
Class Method Details
.cmd(command, output: false) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run a command
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lastpass-api/utils.rb', line 17 def self.cmd( command, output: false ) puts "RUN COMMAND: #{command}".green if Lastpass.verbose @stdout = '' Open3::popen3( command ) do |stdin, stdout, stderr, wait_thr| stdout.sync = true while line = stdout.gets puts line if Lastpass.verbose || output @stdout << line end exit_status = wait_thr.value unless exit_status.success? puts "COMMAND: #{command}".red if Lastpass.verbose stderr_text = stderr.read puts stderr_text.red if Lastpass.verbose raise StandardError, "Command: '#{command}', Stdout: '#{stdout.read}', Stderr: '#{stderr_text}'" end end return @stdout rescue Errno::ENOENT => e puts "COMMAND: #{command}".red if Lastpass.verbose puts "#{e}".red if Lastpass.verbose raise StandardError, "Command: '#{command}', Error: '#{e}'" end |