Skip to content

Commit

Permalink
On 1.9, Kernel.system returns nil if exec fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Apr 9, 2012
1 parent 317d2d4 commit c5150d0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
23 changes: 0 additions & 23 deletions kernel/common/process.rb
Expand Up @@ -710,29 +710,6 @@ def fork(&block)
end
module_function :fork

def system(prog, *args)
pid = Process.fork
if pid
Process.waitpid(pid)
$?.exitstatus == 0
else
begin
Kernel.exec(prog, *args)
rescue Exception => e
if $DEBUG
e.render("Unable to execute subprogram", STDERR)
end
exit! 1
end

if $DEBUG
STDERR.puts "Unable to execute subprogram - exec silently returned"
end
exit! 1
end
end
module_function :system

def `(str) #`
str = StringValue(str) unless str.kind_of?(String)
pid, output = Process.replace(str)
Expand Down
25 changes: 25 additions & 0 deletions kernel/common/process18.rb
Expand Up @@ -26,3 +26,28 @@ def self.exec(cmd, *args)
end
end
end

module Kernel
def system(prog, *args)
pid = Process.fork
if pid
Process.waitpid(pid)
$?.exitstatus == 0
else
begin
Kernel.exec(prog, *args)
rescue Exception => e
if $DEBUG
e.render("Unable to execute subprogram", STDERR)
end
exit! 1
end

if $DEBUG
STDERR.puts "Unable to execute subprogram - exec silently returned"
end
exit! 1
end
end
module_function :system
end
27 changes: 27 additions & 0 deletions kernel/common/process19.rb
Expand Up @@ -69,3 +69,30 @@ def self.exec(environment_or_cmd, *args)
end
end
end

module Kernel
def system(prog, *args)
IO.pipe do |read, write|
pid = Process.fork do
read.close

begin
Kernel.exec(prog, *args)
ensure
write.write false
exit! 1
end
end

write.close
Process.waitpid(pid)

if read.eof?
$?.exitstatus == 0
else
nil
end
end
end
module_function :system
end
1 change: 0 additions & 1 deletion spec/tags/19/ruby/core/kernel/system_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/tags/20/ruby/core/kernel/system_tags.txt

This file was deleted.

0 comments on commit c5150d0

Please sign in to comment.