Package org.jline.shell
Class CommandSession
java.lang.Object
org.jline.shell.CommandSession
Encapsulates the execution context for a command, including the terminal,
I/O streams, session variables, working directory, and job state.
- Since:
- 4.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new command session with the system's standard I/O streams.CommandSession(Terminal terminal) Creates a new command session with the specified terminal.CommandSession(Terminal terminal, InputStream in, PrintStream out, PrintStream err) Creates a new command session with the specified terminal and I/O streams. -
Method Summary
Modifier and TypeMethodDescriptionerr()Returns the error stream.Returns the current foreground job.fork(InputStream in, PrintStream out, PrintStream err) Creates a child session that shares the same terminal but uses independent I/O streams.Returns the value of a session variable.in()Returns the input stream.intReturns the exit code of the last executed command.out()Returns the output stream.voidSets a session variable.Removes a session variable.voidsetErr(PrintStream err) Sets the error stream.voidsetForegroundJob(Job foregroundJob) Sets the current foreground job.voidsetIn(InputStream in) Sets the input stream.voidsetLastExitCode(int lastExitCode) Sets the exit code of the last executed command.voidsetOut(PrintStream out) Sets the output stream.voidsetWorkingDirectory(Path workingDirectory) Sets the working directory.terminal()Returns the terminal for this session.Returns all session variables.Returns the working directory.
-
Constructor Details
-
CommandSession
public CommandSession()Creates a new command session with the system's standard I/O streams. The terminal will be null. -
CommandSession
Creates a new command session with the specified terminal. I/O streams are derived from the terminal.- Parameters:
terminal- the terminal
-
CommandSession
Creates a new command session with the specified terminal and I/O streams.- Parameters:
terminal- the terminalin- the input streamout- the output streamerr- the error stream
-
-
Method Details
-
terminal
Returns the terminal for this session.- Returns:
- the terminal, or null if not associated
-
in
-
out
-
setOut
-
setIn
-
err
-
setErr
-
get
-
put
-
remove
-
variables
-
workingDirectory
Returns the working directory.- Returns:
- the working directory, or null
-
setWorkingDirectory
Sets the working directory.- Parameters:
workingDirectory- the working directory
-
lastExitCode
public int lastExitCode()Returns the exit code of the last executed command.- Returns:
- the last exit code
-
setLastExitCode
public void setLastExitCode(int lastExitCode) Sets the exit code of the last executed command.- Parameters:
lastExitCode- the exit code
-
foregroundJob
-
setForegroundJob
Sets the current foreground job.- Parameters:
foregroundJob- the foreground job
-
fork
Creates a child session that shares the same terminal but uses independent I/O streams.The child session gets a copy of the current variables and working directory. This is used for concurrent pipeline execution where each stage needs its own I/O streams.
- Parameters:
in- the input stream for the child sessionout- the output stream for the child sessionerr- the error stream for the child session- Returns:
- a new child session
-