public static int raise(int pid, int sig) { PtyHelpers.OSFacade m_jpty = PtyHelpers.getInstance(); int status = m_jpty.killpg(pid, sig); if (status == -1) { status = m_jpty.kill(pid, sig); } return status; }
/** * Terminates or signals the process with the given PID. * * @param pid the process ID to terminate or signal; * @param signal the signal number to send, for example, 9 to terminate the * process. * @return a value of <tt>0</tt> upon success, or a non-zero value in case of * an error. */ public static int signal(int pid, int signal) { return getOsFacade().kill(pid, signal); }
public static int execPty(String full_path, String[] argv, String[] envp, String dirpath, String pts_name, int fdm, String err_pts_name, int err_fdm, boolean console) { PtyExecutor executor = getPtyExecutor(); return executor.execPty(full_path, argv, envp, dirpath, pts_name, fdm, err_pts_name, err_fdm, console); }
private static int changeWindowSize(int fd, WinSize ws) { return PtyHelpers.getInstance().setWinSize(fd, ws); }
public static String strerror() { return getOsFacade().strerror(errno()); }
public Pty(boolean console) throws IOException { myConsole = console; Pair<Integer, String> masterSlave = openMaster(console); myMaster = masterSlave.first; mySlaveName = masterSlave.second; if (mySlaveName == null) { throw new IOException("Util.exception.cannotCreatePty"); } myIn = new PTYInputStream(this); myOut = new PTYOutputStream(this); JTermios.pipe(myPipe); }
/** * Reports the window size for the given file descriptor. * * @param fd the file descriptor to report the window size for; * @param ws the window size to place the results in. * @return 0 upon success, or -1 upon failure. */ public static int getWinSize(int fd, WinSize ws) { return getOsFacade().getWinSize(fd, ws); }
/** * Sets the window size for the given file descriptor. * * @param fd the file descriptor to set the window size for; * @param ws the new window size to set. * @return 0 upon success, or -1 upon failure. */ public static int setWinSize(int fd, WinSize ws) { return getOsFacade().setWinSize(fd, ws); }
/** * Blocks and waits until the given PID either terminates, or receives a * signal. * * @param pid the process ID to wait for; * @param stat an array of 1 integer in which the status of the process is * stored; * @param options the bit mask with options. */ public static int waitpid(int pid, int[] stat, int options) { return getOsFacade().waitpid(pid, stat, options); }
/** * Not public as this method <em>replaces</em> the current process and * therefore should be used with caution. * * @param command the command to execute. */ private static int execve(String command, String[] argv, String[] env) { return getOsFacade().execve(command, argv, env); }
public static void chdir(String dirpath) { getOsFacade().chdir(dirpath); }
@Override public void setWinSize(WinSize winSize) { myPty.setTerminalSize(winSize); if (myErrPty != null) { myErrPty.setTerminalSize(winSize); } Pty.raise(pid, SIGWINCH); }
private Pair<Integer, String> openMaster(boolean console) { Pair<Integer, String> master = ptyMasterOpen(); if (master.first >= 0) { // turn off echo if (console) { setNoEcho(master.first); } } return master; }
public int interruptCTRLC() { // if (Platform.getOS().equals(Platform.OS_WIN32)) { // return raise(pid, CTRLC); // } return interrupt(); }
@Override public void write(int b) throws IOException { byte[] buf = new byte[1]; buf[0] = (byte) b; write(buf, 0, 1); }
int exec(String[] cmd, String[] envp, String dirname, String slaveName, int masterFD, String errSlaveName, int errMasterFD, boolean console) throws IOException { int pid = -1; if (cmd == null) { return pid; } if (envp == null) { return pid; } return PtyHelpers.execPty(cmd[0], cmd, envp, dirname, slaveName, masterFD, errSlaveName, errMasterFD, console); }
/** * Tests whether the process with the given process ID is alive or terminated. * * @param pid the process-ID to test. * @return <code>true</code> if the process with the given process ID is * alive, <code>false</code> if it is terminated. */ public static boolean isProcessAlive(int pid) { int[] stat = {-1}; int result = PtyHelpers.waitpid(pid, stat, WNOHANG); return (result == 0) && (stat[0] < 0); }
@Override public int execPty(String full_path, String[] argv, String[] envp, String dirpath, String pts_name, int fdm, String err_pts_name, int err_fdm, boolean console) { return myPty4j.exec_pty(full_path, argv, envp, dirpath, pts_name, fdm, err_pts_name, err_fdm, console); }
/** * 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; }
/** * See java.lang.Process#getOutputStream (); The client is responsible for closing the stream explicitly. */ @Override public synchronized OutputStream getOutputStream() { if (null == out) { out = myPty.getOutputStream(); } return out; }