static boolean WIFEXITED(int status) { return _WSTATUS(status) == 0; }
@Override public void close() throws IOException { myPty.close(); } }
public void close() throws IOException { if (myMaster != -1) { synchronized (myFDLock) { if (myMaster != -1) { try { int status = close0(myMaster); if (status == -1) { throw new IOException("Close error"); } } finally { myMaster = -1; } } } } }
/** * See java.lang.Process#getErrorStream (); The client is responsible for closing the stream explicitly. */ @Override public synchronized InputStream getErrorStream() { if (null == err) { if (!myPty.isConsole()) { // If Pty is used and it's not in "Console" mode, then stderr is redirected to the Pty's output stream. // Therefore, return a dummy stream for error stream. err = new InputStream() { @Override public int read() { return -1; } }; } else { err = myErrPty.getInputStream(); } } return err; }
environment = new String[0]; final String slaveName = pty.getSlaveName(); final int masterFD = pty.getMasterFD(); final String errSlaveName = errPty == null ? null : errPty.getSlaveName(); final int errMasterFD = errPty == null ? -1 : errPty.getMasterFD(); final boolean console = pty.isConsole(); retry = false; try { myPty.setTerminalSize(size); } catch (IllegalStateException e) { if (JTermios.errno() == ENOTTY)
public static int wait0(int pid) { PtyHelpers.OSFacade m_jpty = PtyHelpers.getInstance(); int[] status = new int[1]; if (pid < 0) { return -1; } for (; ; ) { if (m_jpty.waitpid(pid, status, 0) < 0) { if (JTermios.errno() == JTermios.EINTR) { // interrupted system call - retry continue; } } break; } if (WIFEXITED(status[0])) { return WEXITSTATUS(status[0]); } return status[0]; }
@Override public void run() { try { pid = execute(myCommand, myEnv, myDir); } catch (Exception e) { pid = -1; myException = e; } // Tell spawner that the process started. synchronized (UnixPtyProcess.this) { UnixPtyProcess.this.notifyAll(); } if (pid != -1) { // Sync with spawner and notify when done. myStatus = waitFor(pid); synchronized (UnixPtyProcess.this) { isDone = true; UnixPtyProcess.this.notifyAll(); } myPty.breakRead(); if (myErrPty != null) myErrPty.breakRead(); } }
@Deprecated public static PtyProcess exec(String[] command, String[] environment, String workingDirectory, boolean console) throws IOException { if (Platform.isWindows()) { return new WinPtyProcess(command, environment, workingDirectory, console); } return new UnixPtyProcess(command, environment, workingDirectory, new Pty(console), console ? new Pty() : null); }
@Deprecated public static int changeWindowsSize(int fd, int width, int height) { return changeWindowSize(fd, new WinSize(width, height)); }
/** * See java.lang.Process#getInputStream (); The client is responsible for closing the stream explicitly. */ @Override public synchronized InputStream getInputStream() { if (null == in) { in = myPty.getInputStream(); } return in; }
private int close0(int fd) throws IOException { int ret = JTermios.close(fd); breakRead(); synchronized (mySelectLock) { JTermios.close(myPipe[0]); JTermios.close(myPipe[1]); myPipe[0] = -1; myPipe[1] = -1; } return ret; }
public UnixPtyProcess(@NotNull PtyProcessOptions options, boolean consoleMode) throws IOException { myPty = new Pty(consoleMode); myErrPty = options.isRedirectErrorStream() ? myPty : (consoleMode ? new Pty() : null); String dir = MoreObjects.firstNonNull(options.getDirectory(), "."); execInPty(options.getCommand(), PtyUtil.toStringArray(options.getEnvironment()), dir, myPty, myErrPty); }
/** * Change terminal window size to given width and height. * <p> * This should only be used when the pseudo terminal is configured for use with a terminal emulation, i.e. when * {@link #isConsole()} returns {@code false}. * </p> * <p> * <strong>Note:</strong> This method may not be supported on all platforms. Known platforms which support this method * are: {@code linux-x86}, {@code linux-x86_64}, {@code solaris-sparc}, {@code macosx}. * </p> * * @param winSize new size structure. */ public final void setTerminalSize(WinSize winSize) { try { int res = changeWindowSize(myMaster, winSize); if (res != 0) { throw new IllegalStateException("Can set new window size. ioctl returns " + res + ", errorno=" + JTermios.errno()); } } catch (UnsatisfiedLinkError e) { if (!setTerminalSizeErrorAlreadyLogged) { setTerminalSizeErrorAlreadyLogged = true; } } }
@Override public void close() throws IOException { myPty.close(); }
@Override protected void finalize() throws Throwable { close(); super.finalize(); }