shellshot 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/shellshot.rb +54 -41
- data/shellshot.gemspec +4 -5
- data/spec/shellshot_spec.rb +12 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/shellshot.rb
CHANGED
@@ -18,10 +18,10 @@ module Shellshot
|
|
18
18
|
|
19
19
|
self.options = options
|
20
20
|
|
21
|
-
prepare_pipes
|
21
|
+
prepare_pipes
|
22
22
|
self.pid = fork do
|
23
|
-
|
24
|
-
redefine_stds
|
23
|
+
close_reading_pipes
|
24
|
+
redefine_stds
|
25
25
|
system_exec(command)
|
26
26
|
end
|
27
27
|
|
@@ -35,6 +35,28 @@ module Shellshot
|
|
35
35
|
true
|
36
36
|
end
|
37
37
|
|
38
|
+
def stderr_contents
|
39
|
+
unless stderr_defined?
|
40
|
+
@stderr_wr.close
|
41
|
+
contents = @stderr_rd.read
|
42
|
+
@stderr_rd.close
|
43
|
+
contents
|
44
|
+
else
|
45
|
+
File.read(stderr_location)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def stdout_contents
|
50
|
+
unless stdout_defined?
|
51
|
+
@stdout_wr.close
|
52
|
+
contents = @stdout_rd.read
|
53
|
+
@stdout_rd.close
|
54
|
+
contents
|
55
|
+
else
|
56
|
+
File.read(stdout_location)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
38
60
|
private
|
39
61
|
|
40
62
|
def wait_for(seconds)
|
@@ -47,10 +69,6 @@ module Shellshot
|
|
47
69
|
end
|
48
70
|
end
|
49
71
|
|
50
|
-
def close_stderr
|
51
|
-
error_tempfile.close
|
52
|
-
end
|
53
|
-
|
54
72
|
def terminate_child_process
|
55
73
|
if pid
|
56
74
|
Process.kill("KILL", pid)
|
@@ -58,60 +76,55 @@ module Shellshot
|
|
58
76
|
end
|
59
77
|
end
|
60
78
|
|
61
|
-
def redefine_stds
|
62
|
-
|
63
|
-
|
64
|
-
$stdout.reopen(combined)
|
65
|
-
$stderr.reopen(combined)
|
66
|
-
else
|
67
|
-
$stdout.reopen(File.open(stdout_location, "w+")) if stdout_location
|
68
|
-
if no_stderr?
|
69
|
-
$stderr.reopen(@wr)
|
70
|
-
else
|
71
|
-
$stderr.reopen(File.open(stderr_location, "w+"))
|
72
|
-
end
|
73
|
-
end
|
79
|
+
def redefine_stds
|
80
|
+
$stdout.reopen(stdout_descriptor)
|
81
|
+
$stderr.reopen(stderr_descriptor)
|
74
82
|
end
|
75
83
|
|
76
84
|
def stderr_location
|
77
85
|
stdall_location || options[:stderr]
|
78
86
|
end
|
79
87
|
|
80
|
-
def no_stderr?
|
81
|
-
!stderr_location
|
82
|
-
end
|
83
|
-
|
84
88
|
def stdout_location
|
85
89
|
stdall_location || options[:stdout]
|
86
90
|
end
|
87
91
|
|
88
|
-
def
|
89
|
-
|
92
|
+
def stderr_descriptor
|
93
|
+
stdall_descriptor || @stderr_wr || File.open(stderr_location, "w+")
|
90
94
|
end
|
91
95
|
|
92
|
-
def
|
93
|
-
@
|
96
|
+
def stdout_descriptor
|
97
|
+
stdall_descriptor || @stdout_wr || File.open(stdout_location, "w+")
|
94
98
|
end
|
95
99
|
|
96
|
-
def
|
97
|
-
if
|
98
|
-
@
|
99
|
-
contents = @rd.read
|
100
|
-
@rd.close
|
101
|
-
contents
|
102
|
-
else
|
103
|
-
File.read(stderr_location)
|
100
|
+
def stdall_descriptor
|
101
|
+
if stdall_location
|
102
|
+
@stdall_descriptor ||= File.open(stdall_location, "w+")
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
107
|
-
def
|
108
|
-
|
106
|
+
def stderr_defined?
|
107
|
+
!!stderr_location
|
109
108
|
end
|
110
109
|
|
111
|
-
def
|
112
|
-
|
113
|
-
@wr.close
|
110
|
+
def stdout_defined?
|
111
|
+
!!stdout_location
|
114
112
|
end
|
113
|
+
|
114
|
+
def stdall_location
|
115
|
+
options[:stdall]
|
116
|
+
end
|
117
|
+
|
118
|
+
def close_reading_pipes
|
119
|
+
@stderr_rd.close unless stderr_defined?
|
120
|
+
@stdout_rd.close unless stdout_defined?
|
121
|
+
end
|
122
|
+
|
123
|
+
def prepare_pipes
|
124
|
+
@stderr_rd, @stderr_wr = IO.pipe unless stderr_defined?
|
125
|
+
@stdout_rd, @stdout_wr = IO.pipe unless stdout_defined?
|
126
|
+
end
|
127
|
+
|
115
128
|
end
|
116
129
|
|
117
130
|
def self.exec(command, options = {})
|
data/shellshot.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{shellshot}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Petyo Ivanov"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-16}
|
13
13
|
s.description = %q{
|
14
14
|
A small library dealing with the obscurities of shell commands, piping and timeouts.
|
15
15
|
Most of the stuff comes from bad experience in http://beanstalkapp.com.
|
@@ -57,4 +57,3 @@ Gem::Specification.new do |s|
|
|
57
57
|
s.add_dependency(%q<SystemTimer>, [">= 0"])
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
data/spec/shellshot_spec.rb
CHANGED
@@ -31,6 +31,18 @@ describe Shellshot do
|
|
31
31
|
lambda { Shellshot.exec %q[ruby -e '$stderr << "problem"; exit 1;'] }.should raise_error(Shellshot::CommandError, "problem")
|
32
32
|
end
|
33
33
|
|
34
|
+
it "should capture stdout by default" do
|
35
|
+
cmd = Shellshot::Command.new
|
36
|
+
cmd.exec %q[ruby -e '$stdout << "test"']
|
37
|
+
cmd.stdout_contents.should == "test"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should capture stderr by default" do
|
41
|
+
cmd = Shellshot::Command.new
|
42
|
+
cmd.exec %q[ruby -e '$stderr << "test"']
|
43
|
+
cmd.stderr_contents.should == "test"
|
44
|
+
end
|
45
|
+
|
34
46
|
end
|
35
47
|
|
36
48
|
# EOF
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shellshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petyo Ivanov
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-16 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|