com.pty4j.PtyProcess Java Examples

The following examples show how to use com.pty4j.PtyProcess. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BashLocalTerminalRunner.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
@Override
protected PtyProcess createProcess(@Nullable String directory) throws ExecutionException {
    // the env setup must add TERM as in the super implementation
    Map<String, String> env = Maps.newHashMap();
    if (cmd.isPassParentEnvironment()) {
        env.putAll(cmd.getParentEnvironment());
    }
    env.putAll(cmd.getEnvironment());

    env.put("TERM", "xterm-256color");
    EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(env, cmd.getCharset());

    try {
        return PtyProcess.exec(getCommand(), env, directory != null ? directory : cmd.getWorkDirectory().getAbsolutePath(), true);
    } catch (IOException e) {
        throw new ExecutionException(e);
    }
}
 
Example #2
Source File: ShTerminalRunner.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void run(@NotNull String command, @NotNull String workingDirectory) {
  TerminalView terminalView = TerminalView.getInstance(myProject);
  ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(TerminalToolWindowFactory.TOOL_WINDOW_ID);
  if (window == null) return;

  ContentManager contentManager = window.getContentManager();
  Pair<Content, Process> pair = getSuitableProcess(contentManager, workingDirectory);
  if (pair != null) {
    try {
      window.activate(null);
      contentManager.setSelectedContent(pair.first);
      runCommand(pair.second, command);
    }
    catch (ExecutionException e) {
      LOG.warn("Error running terminal", e);
    }
  }
  else {
    terminalView.createNewSession(new LocalTerminalDirectRunner(myProject) {
      @Override
      protected PtyProcess createProcess(@Nullable String directory, @Nullable String commandHistoryFilePath) throws ExecutionException {
        PtyProcess process = super.createProcess(workingDirectory, commandHistoryFilePath);
        runCommand(process, command);
        return process;
      }
    });
  }
}
 
Example #3
Source File: TerminalService.java    From cloudterm with MIT License 5 votes vote down vote up
private void initializeProcess() throws Exception {
    if(isReady){
        return;
    }
    String userHome = System.getProperty("user.home");
    Path dataDir = Paths.get(userHome).resolve(".terminalfx");
    IOHelper.copyLibPty(dataDir);

    if (Platform.isWindows()) {
        this.termCommand = "cmd.exe".split("\\s+");
    } else {
        this.termCommand = "/bin/bash -i".split("\\s+");
    }

    if(Objects.nonNull(shellStarter)){
        this.termCommand = shellStarter.split("\\s+");
    }

    Map<String, String> envs = new HashMap<>(System.getenv());
    envs.put("TERM", "xterm");

    System.setProperty("PTY_LIB_FOLDER", dataDir.resolve("libpty").toString());

    this.process = PtyProcess.exec(termCommand, envs, userHome);

    process.setWinSize(new WinSize(columns, rows));
    this.inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    this.errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
    this.outputWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

    ThreadHelper.start(() -> {
        printReader(inputReader);
    });

    ThreadHelper.start(() -> {
        printReader(errorReader);
    });
    this.isReady = true;

}
 
Example #4
Source File: ProcessTtyConnector.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ProcessTtyConnector(PtyProcess process, Charset charset) {
    this.process = process;
    this.charset = charset;
    this.inputStream = process.getInputStream();
    this.outputStream = process.getOutputStream();
    this.reader = new InputStreamReader(inputStream, charset);
}
 
Example #5
Source File: TerminalEmulator.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TerminalEmulator(String termId, SocketIOSessionOutbound outbound, String[]command, Map<String, String> envs, String workingDirectory) throws IOException {
    PtyProcess pty = PtyProcess.exec(command, envs, workingDirectory);// working dir

    this.termId = termId;
    this.outbound = outbound;
    this.ttyConnector = new ProcessTtyConnector(pty, charset);
}
 
Example #6
Source File: TerminalService.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private void initializeProcess() throws Exception {
  LOGGER.info("initialize TerminalService Process");

  String userHome = System.getProperty("user.home");
  Path dataDir = Paths.get(userHome).resolve(".terminalfx");
  IOHelper.copyLibPty(dataDir);

  boolean isWindows = System.getProperty("os.name").startsWith("Windows");
  if (isWindows) {
    this.termCommand = "cmd.exe".split("\\s+");
  } else {
    this.termCommand = "/bin/bash -i".split("\\s+");
  }

  Map<String, String> envs = new HashMap<>(System.getenv());
  envs.put("TERM", "xterm");

  System.setProperty("PTY_LIB_FOLDER", dataDir.resolve("libpty").toString());

  this.process = PtyProcess.exec(termCommand, envs, userHome);

  process.setWinSize(new WinSize(columns, rows));
  this.inputReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
  this.errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
  this.outputWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));

  TerminalService.startThread(() -> {
    printReader(inputReader);
  });

  TerminalService.startThread(() -> {
    printReader(errorReader);
  });

  process.waitFor();
}
 
Example #7
Source File: Terminal.java    From TerminalFX with MIT License 5 votes vote down vote up
private void initializeProcess() throws Exception {
    final Path dataDir = getDataDir();
    if (SystemUtils.IS_OS_WINDOWS) {
        this.termCommand = getTerminalConfig().getWindowsTerminalStarter().split("\\s+");
    } else {
        this.termCommand = getTerminalConfig().getUnixTerminalStarter().split("\\s+");
    }

    final Map<String, String> envs = new HashMap<>(System.getenv());
    envs.put("TERM", "xterm");

    System.setProperty("PTY_LIB_FOLDER", dataDir.resolve("libpty").toString());

    if (Objects.nonNull(terminalPath) && Files.exists(terminalPath)) {
        this.process = PtyProcess.exec(termCommand, envs, terminalPath.toString());
    } else {
        this.process = PtyProcess.exec(termCommand, envs);
    }

    columnsProperty().addListener(evt -> updateWinSize());
    rowsProperty().addListener(evt -> updateWinSize());
    updateWinSize();
    setInputReader(new BufferedReader(new InputStreamReader(process.getInputStream())));
    setErrorReader(new BufferedReader(new InputStreamReader(process.getErrorStream())));
    setOutputWriter(new BufferedWriter(new OutputStreamWriter(process.getOutputStream())));
    focusCursor();

    countDownLatch.countDown();

    process.waitFor();
}
 
Example #8
Source File: BashLocalTerminalRunner.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
@Override
protected ProcessHandler createProcessHandler(PtyProcess process) {
    if (processHandler == null) {
        processHandler = super.createProcessHandler(process);
    }
    return processHandler;
}
 
Example #9
Source File: PtyCommandLine.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Process startProcessWithPty(@Nonnull 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());
}
 
Example #10
Source File: TerminalTab.java    From TerminalFX with MIT License 4 votes vote down vote up
public PtyProcess getProcess() {
    return terminal.getProcess();
}
 
Example #11
Source File: Terminal.java    From TerminalFX with MIT License 4 votes vote down vote up
public PtyProcess getProcess() {
    return process;
}
 
Example #12
Source File: BashLocalTerminalRunner.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
protected String getTerminalConnectionName(PtyProcess process) {
    return "BashSupport " + scriptName;
}