You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pty4J - Pseudo terminal(PTY) implementation in Java.
This is a Java implementation of PTY. Written in JNA with native code to make fork of a process.
It is based on two projects that provide the same functionality: JPty
and elt.
While JPty is pretty good and written using only JNA it suffers from a
hang on Mac OS X when Java is under debug (jawi/JPty#2), because
fork doesn't work well in java.
elt works ok, but it has mostly native code(using JNI).
So this one is a mix of the other two: a port of elt to JNA in the style it is made in JPty with only
fork and process exec written in native.
Also pty4j implements java interface for pty for windows, using WinPty library.
String[] cmd = { "/bin/sh", "-l" };
Map<String, String> env = new HashMap<>(System.getenv());
if (!env.containsKey("TERM")) env.put("TERM", "xterm");
PtyProcess process = new PtyProcessBuilder().setCommand(cmd).setEnvironment(env).start();
OutputStream os = process.getOutputStream();
InputStream is = process.getInputStream();
// ... work with the streams ...
// wait until the PTY child process is terminated
int result = process.waitFor();
The operating systems currently supported by pty4j are: Linux, OSX, Windows and FreeBSD.