lib/shellshot.rb in shellshot-0.4.0 vs lib/shellshot.rb in shellshot-0.4.1
- old
+ new
@@ -34,22 +34,22 @@
true
end
def stderr_contents
- unless stderr_defined?
+ @stderr_contents ||= unless stderr_defined?
@stderr_wr.close
contents = @stderr_rd.read
@stderr_rd.close
contents
else
File.read(stderr_location)
end
end
def stdout_contents
- unless stdout_defined?
+ @stdout_contents ||= unless stdout_defined?
@stdout_wr.close
contents = @stdout_rd.read
@stdout_rd.close
contents
else
@@ -80,15 +80,15 @@
$stdout.reopen(stdout_descriptor)
$stderr.reopen(stderr_descriptor)
end
def stderr_location
- stdall_location || options[:stderr]
+ stdall_location || (options[:stderr] == false ? null_location : options[:stderr])
end
def stdout_location
- stdall_location || options[:stdout]
+ stdall_location || (options[:stdout] == false ? null_location : options[:stdout])
end
def stderr_descriptor
stdall_descriptor || @stderr_wr || File.open(stderr_location, "w+")
end
@@ -102,28 +102,32 @@
@stdall_descriptor ||= File.open(stdall_location, "w+")
end
end
def stderr_defined?
- !!stderr_location
+ !stderr_location.nil?
end
def stdout_defined?
- !!stdout_location
+ !stdout_location.nil?
end
def stdall_location
- options[:stdall]
+ options[:stdall] == false ? null_location : options[:stdall]
end
def close_reading_pipes
@stderr_rd.close unless stderr_defined?
@stdout_rd.close unless stdout_defined?
end
def prepare_pipes
@stderr_rd, @stderr_wr = IO.pipe unless stderr_defined?
@stdout_rd, @stdout_wr = IO.pipe unless stdout_defined?
+ end
+
+ def null_location
+ "/dev/null"
end
end
def self.exec(command, options = {})