Java Examples for com.pty4j.PtyProcess
The following java examples will help you to understand the usage of com.pty4j.PtyProcess. These source code samples are taken from different open source projects.
Example 1
| Project: JFTClient-master File: LocalTerminal.java View source code |
public void connect() throws IOException {
if (localTerminalPanel == null) {
throw new IllegalStateException("local terminal panel is not set");
}
if (pty != null && pty.isAlive()) {
return;
}
String[] cmd = { "/bin/bash", "-i" };
Map<String, String> envs = new HashMap<>(System.getenv());
// for OS X
envs.remove("TERM_PROGRAM");
envs.put("TERM", "vt102");
pty = PtyProcess.exec(cmd, envs, System.getProperty("user.home"));
OutputStream os = pty.getOutputStream();
InputStream is = pty.getInputStream();
PrintStream printStream = new PrintStream(os, true);
localTerminalPanel.setPrintStream(printStream);
Runnable run = new TerminalWatcher(is, localTerminalPanel.getTextArea());
thread = new Thread(run);
thread.start();
}Example 2
| Project: domainmath-ide-master File: ExternalEngine.java View source code |
public final TtyConnector createTtyConnector() {
try {
Map<String, String> envs = Maps.newHashMap(System.getenv());
envs.put("TERM", "xterm-256color");
String[] command = new String[] { cmd };
PtyProcess process = PtyProcess.exec(command, envs, null);
return new PtyMain.LoggingPtyProcessTtyConnector(process, Charset.forName("UTF-8"));
} catch (Exception e) {
throw new IllegalStateException(e);
}
}Example 3
| Project: intellij-community-master File: LocalTerminalDirectRunner.java View source code |
@Override protected PtyProcess createProcess(@Nullable String directory) throws ExecutionException { Map<String, String> envs = new HashMap<>(System.getenv()); if (!SystemInfo.isWindows) { envs.put("TERM", "xterm-256color"); } if (SystemInfo.isMac) { EnvironmentUtil.setLocaleEnv(envs, myDefaultCharset); } String[] command = getCommand(envs); for (LocalTerminalCustomizer customizer : LocalTerminalCustomizer.EP_NAME.getExtensions()) { try { command = customizer.customizeCommandAndEnvironment(myProject, command, envs); if (directory == null) { directory = customizer.getDefaultFolder(myProject); } } catch (Exception e) { LOG.error("Exception during customization of the terminal session", e); } } try { return PtyProcess.exec(command, envs, directory != null ? directory : TerminalProjectOptionsProvider.Companion.getInstance(myProject).getStartingDirectory()); } catch (IOException e) { throw new ExecutionException(e); } }
Example 4
| Project: consulo-master File: PtyCommandLine.java View source code |
@NotNull
public Process startProcessWithPty(@NotNull List<String> commands, boolean console) throws IOException {
Map<String, String> env = new HashMap<>();
setupEnvironment(env);
if (isRedirectErrorStream()) {
LOG.error("Launching process with PTY and redirected error stream is unsupported yet");
}
String[] command = ArrayUtil.toStringArray(commands);
File workDirectory = getWorkDirectory();
String directory = workDirectory != null ? workDirectory.getPath() : null;
boolean cygwin = myUseCygwinLaunch && SystemInfo.isWindows;
return PtyProcess.exec(command, env, directory, console, cygwin, getPtyLogFile());
}