PageRenderTime 35ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/system_command.rb

https://bitbucket.org/daenoor/redmine_bitbucket
Ruby | 26 lines | 22 code | 2 blank | 2 comment | 1 complexity | a4d8d8fbcc135ab3515f0edd394ffe97 MD5 | raw file
  1. class SystemCommand
  2. # Executes shell command. Returns true if the shell command exits with a success status code
  3. def self.exec(command)
  4. logger.debug { "BitbucketPlugin: Executing command: '#{command}'" }
  5. # Get a path to a temp file
  6. logfile = Tempfile.new('bitbucket_plugin_exec')
  7. logfile.close
  8. success = Kernel.system("#{command} > #{logfile.path} 2>&1")
  9. output_from_command = File.readlines(logfile.path)
  10. if success
  11. logger.debug { "BitbucketPlugin: Command output: #{output_from_command.inspect}"}
  12. else
  13. logger.error { "BitbucketPlugin: Command '#{command}' didn't exit properly. Full output: #{output_from_command.inspect}"}
  14. end
  15. return success
  16. ensure
  17. logfile.unlink unless logfile.nil?
  18. end
  19. def self.logger
  20. ::Rails.logger
  21. end
  22. end