eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'UnixPTYStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: UnixPTYStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--PositionableStream
            |
            +--WriteStream
               |
               +--ReadWriteStream
                  |
                  +--ExternalStream
                     |
                     +--NonPositionableExternalStream
                        |
                        +--PipeStream
                           |
                           +--UnixPTYStream

Package:
stx:libbasic2
Category:
OS-Unix
Version:
rev: 1.12 date: 2018/01/17 12:59:04
user: cg
file: UnixPTYStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


These are much like PipeStreams, but allow bi-directional communication
with a Unix command. (i.e. everything written to the PTYStream is seen
by the commands standard-input, everything written by the command to its
stdErr or stdOut can be read from me.

In addition, sending control characters (such as INTR or QUIT),
will be handled by the command as a signal (unless the command changed
its standard input to raw mode).


Related information:

    TerminalView
    PipeStream
    ExternalStream
    FileStream
    Socket
    OperatingSystem

Class protocol:

blocked instance creation
o  readingFrom: commandString
(comment from inherited method)
create and return a new pipeStream which can read from the unix command
given by commandString.
The command's error output is send to my own error output.

o  readingFrom: commandString errorDisposition: handleError inDirectory: aDirectory
(comment from inherited method)
similar to #readingFrom, but changes the directory while
executing the command. Use this if a command is to be
executed in another directory, to avoid any OS dependencies
in your code.
errorDisposition may be a stream or one of #discard, #inline or #stderr (default).
#discard causes stderr to be discarded (/dev/null),
#inline causes it to be merged into the PipeStream and
#stderr causes it to be written to smalltalk's own stderr.
a stream causes stderr to be sent to that stream (internal or external)
Nil is treated like #stderr

o  readingFrom: commandString inDirectory: aDirectory
(comment from inherited method)
similar to #readingFrom, but changes the directory while
executing the command. Use this if a command is to be
executed in another directory, to avoid any OS dependencies
in your code.
The command's error output is send to my own error output.

o  writingTo: commandString
(comment from inherited method)
create and return a new pipeStream which can write to the unix command
given by command.

o  writingTo: commandString inDirectory: aDirectory
(comment from inherited method)
create and return a new pipeStream which can write to the unix command
given by commandString. The command is executed in the given directory.

instance creation
o  to: commandString
create and return a new ptyStream which can read/write to the unix command
given by commandString.


Instance protocol:

private
o  openPTYFor: aCommandString withMode: openMode inDirectory: aDirectory
open a pty to the unix command in commandString

o  to: command
setup the receiver to read/write to command

testing
o  atEnd
(comment from inherited method)
return true, if position is at end.
Notice: this is a blocking operation, as we do not know in advance,
if there will be anything to read
(i.e. if the partner will send more or close the stream).
If you want to check for available data,
use nextAvailable:, or canReadWithoutBlocking


Examples:


that one is not special (could be done with a PipeStream):
  |pty|

  pty := UnixPTYStream to:'ls -l'.
  [pty atEnd] whileFalse:[
      Transcript showCR:(pty nextLine).
  ].
  pty close.
prove (done with a PipeStream):
  |pty|

  pty := PipeStream readingFrom:'ls -l'.
  [pty atEnd] whileFalse:[
      Transcript showCR:(pty nextLine).
  ].
  pty close.
but that one is not possible with a PipeStream (simulating an editor session):
  |pty|

  pty := UnixPTYStream to:'ed'.
  [
      [pty atEnd] whileFalse:[
          Transcript showCR:(pty nextLine).
      ].
      pty close.
  ] forkAt:9.

  pty nextPutLine:'r Make.proto'.
  pty nextPutLine:'1,2d'.
  pty nextPutLine:'1,$s/#/+++++++/'.
  pty nextPutLine:'w xxx'.
  pty nextPutLine:'q'.
and that one is even better ... (simulating a login session):
  |pty password command|

  pty := UnixPTYStream to:'ssh 127.0.0.1'.
  [
      [pty atEnd] whileFalse:[
          Transcript show:(pty next).
      ].
      pty close.
  ] forkAt:9.

  password := Dialog requestPassword:'password'.
  pty nextPutLine:password.
  command := Dialog request:'command'.
  pty nextPutLine:command.
  pty nextPutLine:'exit'.


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Mon, 26 Feb 2024 13:23:56 GMT