Java 프로그램 내에서 VI를 시작하고 계속하기 전에 VI를 종료 할 때까지 기다리고 싶습니다. 여기에 내가 현재 가지고있는 코드는 다음과 같습니다commons-exec에서 Java 내에서 VI를 시작하려면 어떻게해야합니까?
...
String previewFileName="test.txt"; // the file to edit
CommandLine cmdLine = new CommandLine("/usr/bin/vi");
cmdLine.addArgument(previewFileName);
cmdLine.addArgument(">/dev/tty");
cmdLine.addArgument("</dev/tty");
Executor executor = new DefaultExecutor();
try
{
DefaultExecuteResultHandler resultHandler = new ResetProcessResultHandler(cmdLine);
executor.execute(cmdLine, resultHandler);
} catch (IOException e)
{
throw new Error("Cannot execute command: /usr/bin/vi " + previewFileName, e);
}
log.info("waiting...");
cmdLine.wait();
log.info("...done");
...
private class ResetProcessResultHandler extends DefaultExecuteResultHandler
{
private final CommandLine mCommandLine;
public ResetProcessResultHandler(CommandLine pCommandLine)
{
mCommandLine = pCommandLine;
}
public void onProcessComplete(int exitValue)
{
log.info("Command complete rc(" + exitValue + ")");
if (exitValue != 0)
{
throw new RuntimeException("VI command error [rc=" + exitValue + "] ");
}
mCommandLine.notify();
}
public void onProcessFailed(ExecuteException e)
{
if (e.getExitValue() != 0)
{
log.error("launch VI error " + e.toString());
throw new RuntimeException("VI command failed [" + e.getCause() + "] ");
}
else
{
log.info("VI complete rc(" + e.getExitValue() + ")");
}
mCommandLine.notify();
}
}
내가받을 출력 :
Vim: output is not to a terminal
Vim: input is not from a terminal
하지만 내가 VI 시작 것처럼 그려진 화면을 볼; VI는 내가 입력 한 문자를 읽지 않습니다.
그래서 .../dev/tty에서 리디렉션하는 것이 트릭을 수행하지 않습니다.
누군가 도움이 필요합니다.
감사합니다,
마크
나는 평민 - 간부와 함께 할 방법을 잘 모르겠어요
vi가 포 그라운드로 가져 오지 않고 사용자의 tty에 연결되어 있기 때문에 (이 질문은 실제로 무엇을 묻고 있는지 분명하게 알 수 있습니다) 작동하지 않습니다. –