@@ -133,6 +133,21 @@ public static CommandResult execCmd(final String command, final boolean isRooted
133
133
return execCmd (new String []{command }, isRooted , true );
134
134
}
135
135
136
+ /**
137
+ * Execute the command.
138
+ *
139
+ * @param command The command.
140
+ * @param envp The environment variable settings.
141
+ * @param isRooted True to use root, false otherwise.
142
+ * @return the single {@link CommandResult} instance
143
+ */
144
+ public static CommandResult execCmd (final String command , final List <String > envp , final boolean isRooted ) {
145
+ return execCmd (new String []{command },
146
+ envp == null ? null : envp .toArray (new String []{}),
147
+ isRooted ,
148
+ true );
149
+ }
150
+
136
151
/**
137
152
* Execute the command.
138
153
*
@@ -144,6 +159,23 @@ public static CommandResult execCmd(final List<String> commands, final boolean i
144
159
return execCmd (commands == null ? null : commands .toArray (new String []{}), isRooted , true );
145
160
}
146
161
162
+ /**
163
+ * Execute the command.
164
+ *
165
+ * @param commands The commands.
166
+ * @param envp The environment variable settings.
167
+ * @param isRooted True to use root, false otherwise.
168
+ * @return the single {@link CommandResult} instance
169
+ */
170
+ public static CommandResult execCmd (final List <String > commands ,
171
+ final List <String > envp ,
172
+ final boolean isRooted ) {
173
+ return execCmd (commands == null ? null : commands .toArray (new String []{}),
174
+ envp == null ? null : envp .toArray (new String []{}),
175
+ isRooted ,
176
+ true );
177
+ }
178
+
147
179
/**
148
180
* Execute the command.
149
181
*
@@ -169,6 +201,40 @@ public static CommandResult execCmd(final String command,
169
201
return execCmd (new String []{command }, isRooted , isNeedResultMsg );
170
202
}
171
203
204
+ /**
205
+ * Execute the command.
206
+ *
207
+ * @param command The command.
208
+ * @param envp The environment variable settings.
209
+ * @param isRooted True to use root, false otherwise.
210
+ * @param isNeedResultMsg True to return the message of result, false otherwise.
211
+ * @return the single {@link CommandResult} instance
212
+ */
213
+ public static CommandResult execCmd (final String command ,
214
+ final List <String > envp ,
215
+ final boolean isRooted ,
216
+ final boolean isNeedResultMsg ) {
217
+ return execCmd (new String []{command }, envp == null ? null : envp .toArray (new String []{}),
218
+ isRooted ,
219
+ isNeedResultMsg );
220
+ }
221
+
222
+ /**
223
+ * Execute the command.
224
+ *
225
+ * @param command The command.
226
+ * @param envp The environment variable settings array.
227
+ * @param isRooted True to use root, false otherwise.
228
+ * @param isNeedResultMsg True to return the message of result, false otherwise.
229
+ * @return the single {@link CommandResult} instance
230
+ */
231
+ public static CommandResult execCmd (final String command ,
232
+ final String [] envp ,
233
+ final boolean isRooted ,
234
+ final boolean isNeedResultMsg ) {
235
+ return execCmd (new String []{command }, envp , isRooted , isNeedResultMsg );
236
+ }
237
+
172
238
/**
173
239
* Execute the command.
174
240
*
@@ -196,6 +262,26 @@ public static CommandResult execCmd(final List<String> commands,
196
262
public static CommandResult execCmd (final String [] commands ,
197
263
final boolean isRooted ,
198
264
final boolean isNeedResultMsg ) {
265
+ return execCmd (commands , null , isRooted , isNeedResultMsg );
266
+ }
267
+
268
+ /**
269
+ * Execute the command.
270
+ *
271
+ * @param commands The commands.
272
+ * @param envp Array of strings, each element of which
273
+ * has environment variable settings in the format
274
+ * <i>name</i>=<i>value</i>, or
275
+ * <tt>null</tt> if the subprocess should inherit
276
+ * the environment of the current process.
277
+ * @param isRooted True to use root, false otherwise.
278
+ * @param isNeedResultMsg True to return the message of result, false otherwise.
279
+ * @return the single {@link CommandResult} instance
280
+ */
281
+ public static CommandResult execCmd (final String [] commands ,
282
+ final String [] envp ,
283
+ final boolean isRooted ,
284
+ final boolean isNeedResultMsg ) {
199
285
int result = -1 ;
200
286
if (commands == null || commands .length == 0 ) {
201
287
return new CommandResult (result , "" , "" );
@@ -207,7 +293,7 @@ public static CommandResult execCmd(final String[] commands,
207
293
StringBuilder errorMsg = null ;
208
294
DataOutputStream os = null ;
209
295
try {
210
- process = Runtime .getRuntime ().exec (isRooted ? "su" : "sh" );
296
+ process = Runtime .getRuntime ().exec (isRooted ? "su" : "sh" , envp , null );
211
297
os = new DataOutputStream (process .getOutputStream ());
212
298
for (String command : commands ) {
213
299
if (command == null ) continue ;
0 commit comments