Class: KrakenMobile::CommandHelper
- Inherits:
-
Object
- Object
- KrakenMobile::CommandHelper
- Defined in:
- lib/kraken-mobile/helpers/command_helper.rb
Instance Method Summary collapse
- #build_command(commands) ⇒ Object
-
#build_export_env_command(env_variables) ⇒ Object
Exports a list of environment variables to the users computer.
- #execute_command(process_number, command) ⇒ Object
- #show_output(output, process_number) ⇒ Object
- #terminal_command_separator ⇒ Object
- #user_is_using_windows ⇒ Object
Instance Method Details
#build_command(commands) ⇒ Object
11 12 13 |
# File 'lib/kraken-mobile/helpers/command_helper.rb', line 11 def build_command commands commands.compact*' ' end |
#build_export_env_command(env_variables) ⇒ Object
Exports a list of environment variables to the users computer.
16 17 18 19 20 21 |
# File 'lib/kraken-mobile/helpers/command_helper.rb', line 16 def build_export_env_command env_variables commands = env_variables.map { |key, value| user_is_using_windows ? "(SET \"#{key}=#{value}\")" : "#{key}=#{value};export #{key}" } commands.join(terminal_command_separator) end |
#execute_command(process_number, command) ⇒ Object
23 24 25 26 |
# File 'lib/kraken-mobile/helpers/command_helper.rb', line 23 def execute_command process_number, command output = open("|#{command}", 'r') { |output| show_output(output, process_number) } exitstatus = $?.exitstatus end |
#show_output(output, process_number) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/kraken-mobile/helpers/command_helper.rb', line 28 def show_output(output, process_number) loop do begin line = output.readline() $stdout.print "#{process_number}> #{line}" $stdout.flush end end rescue EOFError end |
#terminal_command_separator ⇒ Object
7 8 9 |
# File 'lib/kraken-mobile/helpers/command_helper.rb', line 7 def terminal_command_separator user_is_using_windows ? ' & ' : ';' end |
#user_is_using_windows ⇒ Object
3 4 5 |
# File 'lib/kraken-mobile/helpers/command_helper.rb', line 3 def user_is_using_windows RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/ end |