File: README.md

package info (click to toggle)
ruby-capture-output 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 128 kB
  • sloc: ruby: 59; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,694 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# capture-output

Capture STDOUT, STDERR or other IO output and return it as a string.

This is useful for testing when you need to start a process and check its output or when you need to check current process output.

## Installing

    gem install capture-output

## Usage

Grab STDOUT:

```ruby
require 'capture-output'

out = Capture.stdout do
	Process.spawn('echo "hello world"')
	STDOUT.puts 'puts'
end
# out contains "hello world\nputs\n"
```

Grab STDERR:

```ruby
require 'capture-output'

out = Capture.stderr do
	Process.spawn('echo "hello world" 1>&2')
	STDERR.puts 'puts'
end
# out contains "hello world\nputs\n"
```

Grab STDOUT and STDERR:

```ruby
require 'capture-output'

err = nil
out = Capture.stdout do
	err = Capture.stderr do
		Process.spawn('echo "hello world out"')
		Process.spawn('echo "hello world err" 1>&2')
	end
end
# err contains "hello world err\n"
# out contains "hello world out\n"
```

## Contributing to caputer-output
 
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

## Copyright

Copyright (c) 2012 Jakub Pastuszek. See LICENSE.txt for
further details.