Method: Jamf::Utility#stdin

Defined in:
lib/jamf/utility.rb

#stdin(line = 0) ⇒ String?

Retrive one or all lines from whatever was piped to standard input.

Standard input is read completely the first time this method is called and the lines are stored as an Array in the module var @stdin_lines

Parameters:

  • line (Integer) (defaults to: 0)

    which line of stdin is being retrieved. The default is zero (0) which returns all of stdin as a single string.

Returns:

  • (String, nil)

    the requested ling of stdin, or nil if it doesn’t exist.



597
598
599
600
601
602
603
604
# File 'lib/jamf/utility.rb', line 597

def stdin(line = 0)
  @stdin_lines ||= ($stdin.tty? ? [] : $stdin.read.lines.map { |l| l.chomp("\n") })

  return @stdin_lines.join("\n") if line <= 0

  idx = line - 1
  @stdin_lines[idx]
end