Sha256: c727b6fdf7c8e02868920c8146a3d8c2968358b9da60273f88fd809056e311fa

Contents?: true

Size: 1.17 KB

Versions: 23

Compression:

Stored size: 1.17 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2020 Eric Crane.  All rights reserved.
#
# Execute a shell command.
#

module GlooLang
  module Verbs
    class Execute < GlooLang::Core::Verb

      KEYWORD = 'execute'.freeze
      KEYWORD_SHORT = 'exec'.freeze
      MISSING_EXPR_ERR = 'Missing Expression!'.freeze

      #
      # Run the verb.
      #
      def run
        if @tokens.token_count < 2
          @engine.err MISSING_EXPR_ERR
          return
        end

        expr = GlooLang::Expr::Expression.new( @engine, @tokens.params )
        cmd = expr.evaluate
        @engine.log.debug "starting cmd: #{cmd}"

        pid = fork { exec( cmd ) }
        Process.wait pid

        # pid = spawn cmd
        # Process.wait pid
        @engine.log.debug "done executing cmd: #{cmd}"

        # system expr.evaluate  #, chdir: Dir.pwd
        # `#{expr.evaluate}`
        # exec expr.evaluate
      end

      #
      # Get the Verb's keyword.
      #
      def self.keyword
        return KEYWORD
      end

      #
      # Get the Verb's keyword shortcut.
      #
      def self.keyword_shortcut
        return KEYWORD_SHORT
      end

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
gloo-lang-1.4.3 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.4.2 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.4.1 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.4.0 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.3.2 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.3.1 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.3.0 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.8 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.7 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.6 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.5 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.4 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.3 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.2 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.1 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.2.0 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.1.0 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.0.2 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.0.1 lib/gloo_lang/verbs/execute.rb
gloo-lang-1.0.0 lib/gloo_lang/verbs/execute.rb