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 void
close()
Closes the entire PTY session.int
exec(String[] cmdarray, String[] envp, String dir)
Executes the given process in the PTYint
getPID()
int
read(byte[] buf)
Implements contract ofInputStream.read(byte[])
void
setTerminalSize(int width, int height)
Implements the contract ofPTY.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 ofProcess.waitFor()
.void
write(byte[] buf)
Implements the contract ofOutputStream.write(byte[])
-
-
-
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. SeeWindowsArgumentQuoter
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 ofProcess.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.
-
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 ofInputStream.read(byte[])
- Throws:
IOException
- See Also:
InputStream.read(byte[])
-
write
public void write(byte[] buf) throws IOException
Implements the contract ofOutputStream.write(byte[])
- Throws:
IOException
- See Also:
OutputStream.write(byte[])
-
setTerminalSize
public void setTerminalSize(int width, int height) throws IOException
Implements the contract ofPTY.setTerminalSize(int, int)
, but throws exceptions that PTY logs.- Throws:
IOException
- See Also:
PTY.setTerminalSize(int, int)
-
-