File tree 2 files changed +26
-2
lines changed
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,26 @@ You can easily read and write data interactively:
67
67
>> runner.read(:how => :partial) # block until some output available
68
68
=> ".\n.\n.\n.\n.\n.\n.\n.\n.\n"
69
69
>> runner.read(:how => :nonblock)
70
- => ""
70
+ => nil
71
71
>> runner.read # block until all output available
72
- => [truncated]
72
+ => ".\n[...]"
73
+
74
+ ## Reactive output
75
+
76
+ You can also receive real-time notifications as data becomes available:
77
+
78
+ >> runner = Rubysh(
79
+ 'examples/on_read_example.sh',
80
+ Rubysh.stdout > :stdout, Rubysh.stderr > :stderr,
81
+ on_read: Proc.new {|target, data| puts "[#{target}]: #{data}"}
82
+ )
83
+ => Command: examples/on_read_example.sh >:stdout 2>:stderr {:on_read=>#<Proc:0x007f8ad3bc5790@(irb):4>}
84
+ >> runner.run
85
+ [stdout]: [1] Hello from stdout
86
+ [stderr]: [1] Hello from stderr
87
+ [stdout]: [2] Hello from stdout
88
+ [stderr]: [2] Hello from stderr
89
+ [...]
73
90
74
91
## API
75
92
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+
3
+ for i in {1..10}; do
4
+ echo " [$i ] Hello from stdout"
5
+ echo >&2 " [$i ] Hello from stderr"
6
+ sleep 1
7
+ done
You can’t perform that action at this time.
0 commit comments