Skip to content

Commit

Permalink
save history when job complete. alibaba#9
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc authored and XhinLiang committed Aug 5, 2019
1 parent afe647d commit 755c51d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.taobao.arthas.core.shell.system.impl;

import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import com.taobao.arthas.core.shell.future.Future;
Expand All @@ -11,6 +13,10 @@
import com.taobao.arthas.core.shell.system.ExecStatus;
import com.taobao.arthas.core.shell.system.Job;
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:[email protected]">Julien Viet</a>
Expand Down Expand Up @@ -234,6 +240,12 @@ public void handle(Integer exitCode) {
}
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));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static FileOutputStream openOutputStream(File file, boolean append) throw
public static void saveCommandHistory(List<int[]> history, File file) {
OutputStream out = null;
try {
out = openOutputStream(file, false);
out = new BufferedOutputStream(openOutputStream(file, false));
for (int[] command: history) {
for (int i : command) {
out.write(i);
Expand Down

0 comments on commit 755c51d

Please sign in to comment.