save history when job complete. #9

This commit is contained in:
hengyunabc 2019-05-15 17:04:19 +08:00
parent 487742dfb0
commit c61fd13763
2 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,8 @@
package com.taobao.arthas.core.shell.system.impl; package com.taobao.arthas.core.shell.system.impl;
import java.io.File;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import com.taobao.arthas.core.shell.future.Future; import com.taobao.arthas.core.shell.future.Future;
@ -11,6 +13,10 @@ import com.taobao.arthas.core.shell.session.Session;
import com.taobao.arthas.core.shell.system.ExecStatus; import com.taobao.arthas.core.shell.system.ExecStatus;
import com.taobao.arthas.core.shell.system.Job; import com.taobao.arthas.core.shell.system.Job;
import com.taobao.arthas.core.shell.system.Process; import com.taobao.arthas.core.shell.system.Process;
import com.taobao.arthas.core.shell.term.Term;
import com.taobao.arthas.core.shell.term.impl.TermImpl;
import com.taobao.arthas.core.util.Constants;
import com.taobao.arthas.core.util.FileUtils;
/** /**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a> * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
@ -234,6 +240,12 @@ public class JobImpl implements Job {
} }
terminateFuture.complete(); terminateFuture.complete();
// save command history
Term term = shell.term();
if (term instanceof TermImpl) {
List<int[]> history = ((TermImpl) term).getReadline().getHistory();
FileUtils.saveCommandHistory(history, new File(Constants.CMD_HISTORY_FILE));
}
} }
} }

View File

@ -104,7 +104,7 @@ public class FileUtils {
public static void saveCommandHistory(List<int[]> history, File file) { public static void saveCommandHistory(List<int[]> history, File file) {
OutputStream out = null; OutputStream out = null;
try { try {
out = openOutputStream(file, false); out = new BufferedOutputStream(openOutputStream(file, false));
for (int[] command: history) { for (int[] command: history) {
for (int i : command) { for (int i : command) {
out.write(i); out.write(i);