Package org.eclipse.cdt.utils.pty
Class ConPTY
- java.lang.Object
-
- org.eclipse.cdt.utils.pty.ConPTY
-
public class ConPTY extends Object
A JNA implementation for ConPTY to provide a Windows native (as opposed to WinPTY) implementation of a PTY. This class should be accessed/created via the PTY class which will use ConPTY when it is available.- Restriction:
- This class is not intended to be referenced by clients.
-
-
Constructor Summary
Constructors Constructor Description ConPTY()Create a new Windows Pseudo Console (ConPTY) that an application can be attached to.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the entire PTY session.intexec(String[] cmdarray, String[] envp, String dir)Executes the given process in the PTYintgetPID()intread(byte[] buf)Implements contract ofInputStream.read(byte[])voidsetTerminalSize(int width, int height)Implements the contract ofPTY.setTerminalSize(int, int), but throws exceptions that PTY logs.static com.sun.jna.MemorytoByteArray(String[] envp)Convert envp to a byte array, encoding UTF_16LE.intwaitFor()Implements the contract ofProcess.waitFor().voidwrite(byte[] buf)Implements the contract ofOutputStream.write(byte[])
-
-
-
Constructor Detail
-
ConPTY
public ConPTY() throws IOExceptionCreate a new Windows Pseudo Console (ConPTY) that an application can be attached to.- Throws:
IOException
-
-
Method Detail
-
exec
public int exec(String[] cmdarray, String[] envp, String dir) throws IOException
Executes the given process in the PTY- Parameters:
cmdarray- Command and arguments that will be quotes using standard Windows rules to make a command line. SeeWindowsArgumentQuoterenvp-dir-- Returns:
- the PID
- Throws:
IOException
-
toByteArray
public static com.sun.jna.Memory toByteArray(String[] envp) throws IOException
Convert envp to a byte array, encoding UTF_16LE. Remember to pass CREATE_UNICODE_ENVIRONMENT to CreateProcess- Throws:
IOException
-
getPID
public int getPID()
-
waitFor
public int waitFor()
Implements the contract ofProcess.waitFor(). This is used byPTY.waitFor(org.eclipse.cdt.utils.spawner.Spawner, int), but in the Spawner case the PID is passed around unnecessarily. This method therefore waits for the process it created only, like how Process#waitFor() behaves.
-
close
public void close() throws IOExceptionCloses the entire PTY session. This will have the side effect of closing all the IO channels at once. The process will also be terminated when the console is closed if it isn't closed already. If the console's host (conhost) is closed then the process won't be automatically terminated. This happens if conhost crashes and the behaviour with winpty is the same in that case.- Throws:
IOException
-
read
public int read(byte[] buf) throws IOExceptionImplements contract ofInputStream.read(byte[])- Throws:
IOException- See Also:
InputStream.read(byte[])
-
write
public void write(byte[] buf) throws IOExceptionImplements the contract ofOutputStream.write(byte[])- Throws:
IOException- See Also:
OutputStream.write(byte[])
-
setTerminalSize
public void setTerminalSize(int width, int height) throws IOExceptionImplements the contract ofPTY.setTerminalSize(int, int), but throws exceptions that PTY logs.- Throws:
IOException- See Also:
PTY.setTerminalSize(int, int)
-
-