Skip to content

Commit d9453db

Browse files
jawshooahsds
authored andcommittedApr 8, 2015
Use ChildProcess to spawn detached processes
As of childprocess 0.5.6, it is possible to check the exit status of a ChildProcess without an error being thrown.
1 parent cc20fc1 commit d9453db

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed
 

Diff for: ‎lib/overcommit/subprocess.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ def spawn(args)
3232
# Spawns a new process in the background using the given array of
3333
# arguments (the first element is the command).
3434
def spawn_detached(args)
35-
# Dissociate process from parent's input/output streams
36-
Process.detach(Process.spawn({}, *args, [:in, :out, :err] => '/dev/null'))
35+
process = ChildProcess.build(*args)
36+
process.detach = true
37+
38+
assign_output_streams(process)
39+
40+
process.start
3741
end
3842

3943
private

Diff for: ‎lib/overcommit/utils.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def execute(args)
129129
# which we do not need to know the result.
130130
#
131131
# @param args [Array<String>]
132-
# @return [Thread] thread watching the resulting child process
132+
# @return [ChildProcess] detached process spawned in the background
133133
def execute_in_background(args)
134134
if args.include?('|')
135135
raise Overcommit::Exceptions::InvalidCommandArgs,

Diff for: ‎spec/overcommit/utils_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
end
164164

165165
it 'executes the command' do
166-
wait_until { subject.stop? } # Make sure process terminated before checking
166+
wait_until { subject.exited? } # Make sure process terminated before checking
167167
File.exist?('some-file').should == true
168168
end
169169
end

0 commit comments

Comments
 (0)
Please sign in to comment.