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
`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
`void` `close()` Closes the entire PTY session.
`int` `exec​(String[] cmdarray, String[] envp, String dir)` Executes the given process in the PTY
`int` `getPID()`
`int` `read​(byte[] buf)` Implements contract of `InputStream.read(byte[])`
`void` `setTerminalSize​(int width, int height)` Implements the contract of `PTY.setTerminalSize(int, int)`, but throws exceptions that PTY logs.
`static com.sun.jna.Memory` `toByteArray​(String[] envp)` Convert envp to a byte array, encoding UTF_16LE.
`int` `waitFor()` Implements the contract of `Process.waitFor()`.
`void` `write​(byte[] buf)` Implements the contract of `OutputStream.write(byte[])`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ConPTY

    public ConPTY()
           throws IOException

Create 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. See `WindowsArgumentQuoter`
  `envp` -
  `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 of `Process.waitFor()`. This is used by {@link PTY#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.

See Also:
  `Process.waitFor()`, `PTY.waitFor(org.eclipse.cdt.utils.spawner.Spawner, int)`

#### close

    public void close()
               throws IOException

Closes 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 IOException

Implements contract of `InputStream.read(byte[])`

Throws:
  `IOException`
See Also:
  `InputStream.read(byte[])`

#### write

    public void write​(byte[] buf)
               throws IOException

Implements the contract of `OutputStream.write(byte[])`

Throws:
  `IOException`
See Also:
  `OutputStream.write(byte[])`

#### setTerminalSize

    public void setTerminalSize​(int width,
                                int height)
                         throws IOException

Implements the contract of `PTY.setTerminalSize(int, int)`, but throws exceptions that PTY logs.

Throws:
  `IOException`
See Also:
  `PTY.setTerminalSize(int, int)`