shellutils 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shellutils.rb +21 -16
- data/lib/shellutils/version.rb +1 -1
- metadata +1 -1
data/lib/shellutils.rb
CHANGED
@@ -115,28 +115,33 @@ module ShellUtils
|
|
115
115
|
|
116
116
|
def exec_cmd_and_clear_password(cmd)
|
117
117
|
puts cmd
|
118
|
-
|
119
|
-
w
|
120
|
-
w.sync = true
|
121
|
-
w.flush
|
122
|
-
if r.expect(/[Pp]assword.*:.*$/, 1)
|
118
|
+
begin
|
119
|
+
PTY.spawn(cmd) do |r, w|
|
123
120
|
w.flush
|
124
|
-
w.
|
121
|
+
w.sync = true
|
125
122
|
w.flush
|
126
|
-
|
123
|
+
if r.expect(/[Pp]assword.*:.*$/, 1)
|
124
|
+
w.flush
|
125
|
+
w.puts(get_sudo_pwd)
|
127
126
|
w.flush
|
128
|
-
|
129
|
-
|
127
|
+
begin
|
128
|
+
w.flush
|
129
|
+
if r.expect(/[Pp]assword.*:.*$/, 1)
|
130
|
+
error("the sudo password is incorrect. password=#{get_sudo_pwd}\nPlease change the password ex) set_sudo_pwd PASSWORD")
|
131
|
+
end
|
132
|
+
rescue
|
130
133
|
end
|
131
|
-
|
134
|
+
end
|
135
|
+
w.flush
|
136
|
+
begin
|
137
|
+
puts r.read
|
138
|
+
rescue Errno::EIO # GNU/Linux raises EIO.
|
139
|
+
rescue IOError
|
132
140
|
end
|
133
141
|
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
rescue Errno::EIO # GNU/Linux raises EIO.
|
138
|
-
rescue IOError
|
139
|
-
end
|
142
|
+
rescue Errno::EIO
|
143
|
+
# If the password prompt does not appear.
|
144
|
+
`#{cmd}`
|
140
145
|
end
|
141
146
|
end
|
142
147
|
|
data/lib/shellutils/version.rb
CHANGED