Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add option to discard output

  • Loading branch information...
commit 6554ce1c83b73a945855bcbb18fbb3b1602a1a5a 1 parent daf5bd2
Alex Suraci and Maria Shaldibina authored
11 em-posix-spawn/lib/em/posix/spawn/child.rb
View
@@ -47,6 +47,7 @@ def initialize(*args)
@input = @options.delete(:input)
@timeout = @options.delete(:timeout)
@max = @options.delete(:max)
+ @discard_output = @options.delete(:discard_output)
@prepend_stdout = @options.delete(:prepend_stdout) || ""
@prepend_stderr = @options.delete(:prepend_stderr) || ""
@options.delete(:chdir) if @options[:chdir].nil?
@@ -220,8 +221,8 @@ def exec!
# watch fds
@cin = EM.watch stdin, WritableStream, (@input || "").dup, "stdin"
- @cout = EM.watch stdout, ReadableStream, @prepend_stdout, "stdout"
- @cerr = EM.watch stderr, ReadableStream, @prepend_stderr, "stderr"
+ @cout = EM.watch stdout, ReadableStream, @prepend_stdout, "stdout", @discard_output
+ @cerr = EM.watch stderr, ReadableStream, @prepend_stderr, "stderr", @discard_output
# register events
@cin.notify_writable = true
@@ -401,8 +402,9 @@ def slice_from_buffer(buffer)
# Maximum buffer size for reading
BUFSIZE = (64 * 1024)
- def initialize(buffer, name, &block)
+ def initialize(buffer, name, discard_output = false, &block)
super(buffer, name, &block)
+ @discard_output = discard_output
@after_read = []
end
@@ -449,7 +451,8 @@ def notify_readable
return if closed?
begin
- @buffer << @io.read_nonblock(BUFSIZE)
+ out = @io.read_nonblock(BUFSIZE)
+ @buffer << out unless @discard_output
@after_read.each { |listener| listener.call(@buffer) }
rescue Errno::EAGAIN, Errno::EINTR
rescue EOFError
11 em-posix-spawn/test/test_child.rb
View
@@ -131,6 +131,17 @@ def test_max
end
end
+ def test_discard_output
+ em do
+ p = Child.new('echo hi', :discard_output => true)
+ p.callback do
+ assert_equal 0, p.out.size
+ assert_equal 0, p.err.size
+ done
+ end
+ end
+ end
+
def test_max_with_child_hierarchy
em do
p = Child.new('/bin/sh', '-c', 'yes', :max => 100_000)
Please sign in to comment.
Something went wrong with that request. Please try again.