frontkick 0.5.2 → 0.5.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +82 -27
- data/lib/frontkick/command.rb +2 -2
- data/lib/frontkick/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb5e819a8afaf32b404b81f3b4d0792aa90f7b9
|
4
|
+
data.tar.gz: 9a35e8fafa3cfecde913653eaf4611a9ace3b70a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 628155e7ae55b811fee9f9727f429b5a6e8b50bf28d722618583b8d82627ce60640ac2263dda02d4c43d75ad03a9ac474483a5c0a170586b27c55e656321bfe8
|
7
|
+
data.tar.gz: 5baf25776ba2790a21c4f9156fdc78fe960fff48dee5357ad6b7e8e655b24549baff06f48c9be1ce66048ac7f0e6087f0e98dbc9aca9463b911480baf21f53dd
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,66 +1,121 @@
|
|
1
1
|
# frontkick [](http://travis-ci.org/sonots/frontkick) [](https://gemnasium.com/sonots/frontkick)
|
2
2
|
|
3
|
-
Frontkick is a gem to execute a command and obtain exit\_code, stdout, stderr simply.
|
3
|
+
Frontkick is a gem to execute a command and obtain exit\_code, stdout, stderr simply.
|
4
4
|
|
5
5
|
## What is This For?
|
6
6
|
|
7
|
-
Ruby's `Kernel.#system` method does not return STDOUT and STDERR.
|
7
|
+
Ruby's `Kernel.#system` method does not return STDOUT and STDERR.
|
8
8
|
Ruby's back quote (``) returns STDOUT, but does not return STDERR.
|
9
9
|
|
10
|
-
With frontkick, you can easily get the exit code, STDOUT, and STDERR.
|
10
|
+
With frontkick, you can easily get the exit code, STDOUT, and STDERR.
|
11
11
|
|
12
12
|
## USAGE
|
13
13
|
|
14
|
-
|
14
|
+
```
|
15
|
+
gem install frontkick
|
16
|
+
```
|
15
17
|
|
16
18
|
### Basic Usage
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
```ruby
|
21
|
+
result = Frontkick.exec("echo *")
|
22
|
+
puts result.successful? #=> true if exit_code is 0
|
23
|
+
puts result.success? #=> alias to successful?, for compatibility with Process::Status
|
24
|
+
puts result.stdout #=> stdout output of the command
|
25
|
+
puts result.stderr #=> stderr output of the command
|
26
|
+
puts result.exit_code #=> exit_code of the command
|
27
|
+
puts result.status #=> alias to exit_code
|
28
|
+
puts result.exitstatus #=> alias to exit_code, for compatibility with Process::Status
|
29
|
+
puts result.duration #=> the time used to execute the command
|
30
|
+
```
|
31
|
+
|
32
|
+
### No Shell
|
33
|
+
|
34
|
+
**String argument**
|
35
|
+
|
36
|
+
When the first argument is a String, the command is executed via shell if the command string includes meta characters of shell such as:
|
37
|
+
|
38
|
+
```
|
39
|
+
* ? {} [] <> () ~ & | \ $ ; ' ` " \n
|
40
|
+
```
|
41
|
+
|
42
|
+
otherwise, the command is not executed via shell.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
result = Frontkick.exec("echo foo") # no shell
|
46
|
+
result = Frontkick.exec("echo *") # with shell
|
47
|
+
```
|
48
|
+
|
49
|
+
The process tree for the latter (with shell) will be like:
|
27
50
|
|
28
|
-
|
51
|
+
```
|
52
|
+
ruby
|
53
|
+
└─ sh -c
|
54
|
+
└── echo *
|
55
|
+
```
|
56
|
+
|
57
|
+
**Array argument**
|
29
58
|
|
30
|
-
|
59
|
+
When the first argument is an Array, The command is not executed via a shell.
|
60
|
+
Note that shell wildcards are not available with this way.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
result = Frontkick.exec(["echo", "*"]) #=> echo the asterisk character
|
64
|
+
```
|
65
|
+
|
66
|
+
The process tree will be like:
|
67
|
+
|
68
|
+
```
|
69
|
+
ruby
|
70
|
+
└─ echo
|
71
|
+
```
|
31
72
|
|
32
73
|
### Dry Run Option
|
33
74
|
|
34
|
-
|
35
|
-
|
75
|
+
```ruby
|
76
|
+
result = Frontkick.exec(["echo", "*"], :dry_run => true)
|
77
|
+
puts result.stdout #=> echo \*
|
78
|
+
```
|
36
79
|
|
37
80
|
### Timeout Option
|
38
81
|
|
39
|
-
|
82
|
+
```ruby
|
83
|
+
Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1) # raises Frontkick::Timeout
|
84
|
+
```
|
40
85
|
|
41
86
|
not to kill timeouted process
|
42
87
|
|
43
|
-
|
88
|
+
```ruby
|
89
|
+
Frontkick.exec("sleep 2 && ls /hoge", :timeout => 1, :timeout_kill => false) # raises Frontkick::Timeout
|
90
|
+
```
|
44
91
|
|
45
92
|
### Exclusive Option
|
46
93
|
|
47
94
|
Prohibit another process to run a command concurrently
|
48
95
|
|
49
|
-
|
96
|
+
```ruby
|
97
|
+
Frontkick.exec("sleep 2 && ls /hoge", :exclusive => "/tmp/frontkick.lock") # raises Fontkick::Locked if locked
|
98
|
+
```
|
50
99
|
|
51
100
|
If you prefer to be blocked:
|
52
101
|
|
53
|
-
|
102
|
+
```ruby
|
103
|
+
Frontkick.exec("sleep 2 && ls /hoge", :exclusive => "/tmp/frontkick.lock", :exclusive_blocking => true)
|
104
|
+
```
|
54
105
|
|
55
106
|
### Redirect Options (:out and :err)
|
56
107
|
|
57
|
-
|
108
|
+
```ruby
|
109
|
+
Frontkick.exec(["ls /something_not_found"], :out => 'stdout.txt', :err => 'stderr.txt')
|
110
|
+
```
|
58
111
|
|
59
112
|
This redirects STDOUT and STDERR into files. In this case, result.stdout, and result.stderr are the given filename.
|
60
113
|
|
61
|
-
|
62
|
-
|
63
|
-
|
114
|
+
```ruby
|
115
|
+
out = File.open('stdout.txt', 'w').tap {|fp| fp.sync = true }
|
116
|
+
err = File.open('stderr.txt', 'w').tap {|fp| fp.sync = true }
|
117
|
+
Frontkick.exec(["ls /something_not_found"], :out => out, :err => err)
|
118
|
+
```
|
64
119
|
|
65
120
|
You can also give IO objects. In this case, result.stdout, and result.stderr are the given IO objects.
|
66
121
|
|
@@ -70,8 +125,8 @@ Other options such as :chdir are treated as options of `Open3.#popen3`.
|
|
70
125
|
|
71
126
|
### Kill Child Process
|
72
127
|
|
73
|
-
|
74
|
-
|
128
|
+
Although sending a signal to a kicked child process directly causes no problem (frontkick process can take care of it),
|
129
|
+
sending a signal to a frontkick process may cause a problem that a child process becomes an orphan process.
|
75
130
|
|
76
131
|
To kill your frontkick process with its child process correctly, send a signal to their **process group** as
|
77
132
|
|
data/lib/frontkick/command.rb
CHANGED
@@ -82,8 +82,8 @@ module Frontkick
|
|
82
82
|
raise Frontkick::Timeout.new(pid, command, opts[:timeout_kill])
|
83
83
|
ensure
|
84
84
|
stdin.close if stdin and !stdin.closed?
|
85
|
-
|
86
|
-
|
85
|
+
stdout.close if stdout and !stdout.closed?
|
86
|
+
stderr.close if stderr and !stderr.closed?
|
87
87
|
wait_thr.kill if wait_thr and !wait_thr.stop?
|
88
88
|
lock_fd.flock(File::LOCK_UN) if lock_fd
|
89
89
|
if opts[:out] and opts[:out].is_a?(String)
|
data/lib/frontkick/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frontkick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|