Class: Lazylead::OS

Inherits:
Object
  • Object
show all
Defined in:
lib/lazylead/os.rb

Overview

Represents a native, operation system.

Author

Yurii Dubinka ([email protected])

Copyright

Copyright © 2019-2020 Yurii Dubinka

License

MIT

Instance Method Summary collapse

Instance Method Details

#run(*cmd) ⇒ Object

TODO:

#/DEV Add support of multiline string literals, not just array of commands

Run OS-oriented command

Parameters:

  • cmd

    The command could be a single string or array of strings. Examples Final command to OS run(“ls”) “ls” => stdout run(“ls”, “-lah”) “ls -lah” => stdout run() N/A => “” run(“ls”, nil, “-lah”) N/A => “” run(“ls”, “”, “-lah”) “ls -lah” => stdout

Returns:

  • stdout Please note, that this is not a raw stdout. The output will be modified by String#scrub! in order to avoid invalid byte sequence in UTF-8 (stackoverflow.com/a/24037885/6916890).



49
50
51
52
53
54
# File 'lib/lazylead/os.rb', line 49

def run(*cmd)
  return "" if cmd.empty? || cmd.any?(&:nil?)
  todo = cmd
  todo = [cmd.first] if cmd.size == 1
  `#{todo.join(" ")}`.scrub!
end