Sha256: 381602767b0b50800bee5d9be3b4be2d88dd23e3e936d7529fdcbc54712befa0

Contents?: true

Size: 971 Bytes

Versions: 8

Compression:

Stored size: 971 Bytes

Contents

module KrakenMobile
	class CommandHelper
		def user_is_using_windows
			RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/
		end

		def terminal_command_separator
			user_is_using_windows ? ' & ' : ';'
		end

		def build_command commands
			commands.compact*' '
		end

    # Exports a list of environment variables to the users computer.
		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

		def execute_command process_number, command
			output = open("|#{command}", 'r') { |output| show_output(output, process_number)  }
			exitstatus = $?.exitstatus
		end

		def show_output(output, process_number)
			loop do
				begin
					line = output.readline()
					$stdout.print "#{process_number}> #{line}"
					$stdout.flush
				end
			end rescue EOFError
		end
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kraken-mobile-1.0.9 lib/kraken-mobile/helpers/command_helper.rb
kraken-mobile-1.0.8 lib/kraken-mobile/helpers/command_helper.rb
kraken-mobile-1.0.5 lib/kraken-mobile/helpers/command_helper.rb
kraken-mobile-1.0.4 lib/kraken-mobile/helpers/command_helper.rb
kraken-mobile-1.0.3 lib/kraken-mobile/helpers/command_helper.rb
kraken-mobile-1.0.2 lib/kraken-mobile/helpers/command_helper.rb
kraken-mobile-1.0.1 lib/kraken-mobile/helpers/command_helper.rb
kraken-mobile-1.0.0 lib/kraken-mobile/helpers/command_helper.rb