Skip to content

Commit 359f376

Browse files
committed
see 11/01 log
1 parent b158245 commit 359f376

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* 17/11/01 完善ShellUtil的Msg换行,感谢香脆的大鸡排
12
* 17/10/30 升级README
23
* 17/10/29 修复6.0内部存储安装失败问题
34
* 17/10/28 替换compile为implementation,provided为compileOnly

utilcode/src/main/java/com/blankj/utilcode/util/ShellUtils.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
public final class ShellUtils {
1717

18+
private static final String LINE_SEP = System.getProperty("line.separator");
19+
1820
private ShellUtils() {
1921
throw new UnsupportedOperationException("u can't instantiate me...");
2022
}
@@ -101,25 +103,29 @@ public static CommandResult execCmd(final String[] commands, final boolean isRoo
101103
for (String command : commands) {
102104
if (command == null) continue;
103105
os.write(command.getBytes());
104-
os.writeBytes("\n");
106+
os.writeBytes(LINE_SEP);
105107
os.flush();
106108
}
107-
os.writeBytes("exit\n");
109+
os.writeBytes("exit" + LINE_SEP);
108110
os.flush();
109111
result = process.waitFor();
110112
if (isNeedResultMsg) {
111113
successMsg = new StringBuilder();
112114
errorMsg = new StringBuilder();
113115
successResult = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
114116
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8"));
115-
String s;
116-
while ((s = successResult.readLine()) != null) {
117-
successMsg.append(System.getProperty("line.separator"));
118-
successMsg.append(System.getProperty("line.separator"));
117+
String line;
118+
if ((line = successResult.readLine()) != null) {
119+
successMsg.append(line);
120+
while ((line = successResult.readLine()) != null) {
121+
successMsg.append(LINE_SEP).append(line);
122+
}
119123
}
120-
while ((s = errorResult.readLine()) != null) {
121-
errorMsg.append("\n");
122-
errorMsg.append(s);
124+
if ((line = errorResult.readLine()) != null) {
125+
errorMsg.append(line);
126+
while ((line = errorResult.readLine()) != null) {
127+
errorMsg.append(LINE_SEP).append(line);
128+
}
123129
}
124130
}
125131
} catch (Exception e) {

0 commit comments

Comments
 (0)