Class: Purple::Run::Child

Inherits:
Object
  • Object
show all
Defined in:
lib/purple/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dir, cmd, *args) ⇒ Child

Returns a new instance of Child.



5
6
7
8
9
10
# File 'lib/purple/process.rb', line 5

def initialize name, dir, cmd, *args
    @out = File.new File.join(dir, name + ".out"), 'w'
    @err = File.new File.join(dir, name + ".err"), 'w'
    @cmd, @args = cmd, args
    @status = @exit_code = nil
end

Instance Attribute Details

#exit_codeObject (readonly)

Returns the value of attribute exit_code.



11
12
13
# File 'lib/purple/process.rb', line 11

def exit_code
  @exit_code
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/purple/process.rb', line 11

def status
  @status
end

Instance Method Details

#startObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/purple/process.rb', line 13

def start
    pid = fork do
        STDOUT.reopen @out
        STDERR.reopen @err
        puts "> #{@cmd} #{@args.join ' '}"
        exec @cmd, *@args
    end
    Thread.new do
        begin
            #puts "DEBUG Purple::Process::Child#start: HERE" if $DEBUG
            @exit_code = Process.waitpid2(pid)[1].exitstatus
            #puts "DEBUG Purple::Process::Child#start: status=#{@exit_code}" if $DEBUG
        ensure
            @status = :done
        end
    end
    #pid
end