class Builtins::Bg

Constants

DEFAULT_LOG_FILE_PREFIX

Public Class Methods

description() click to toggle source
# File lib/builtins/background.rb, line 10
def description
        "runs the given command in a background session"
end
log_filename() click to toggle source
# File lib/builtins/background.rb, line 14
def log_filename
        Options.get("background.log_filename") || "#{DEFAULT_LOG_FILE_PREFIX}#{Ops.project_name}"
end

Public Instance Methods

run() click to toggle source
# File lib/builtins/background.rb, line 19
def run
        subprocess = fork do
                set_bglog_file_permissions
                run_ops(args)
        end

        Process.detach(subprocess)
end

Private Instance Methods

run_ops(args) click to toggle source
# File lib/builtins/background.rb, line 34
def run_ops(args)
        Output.notice("Running '#{args.join(' ')}' with stderr and stdout redirected to '#{Background.log_filename}'")
        $stdout.sync = $stderr.sync = true
        $stdout.reopen(Background.log_filename, "w")
        $stderr.reopen($stdout)

        Ops.new(args).run
end
set_bglog_file_permissions() click to toggle source
# File lib/builtins/background.rb, line 30
def set_bglog_file_permissions
        File.new(Background.log_filename, "w").chmod(0o600)
end