[ENH][GOODIE] CommandShell V3.0 (Windows support with OSProcess 3.0)

David T. Lewis lewis at mail.msen.com
Tue Mar 12 02:19:03 UTC 2002


CommandShell 3.0
David T. Lewis, 10 March 2002
Previous released version: CommandShell 1.6
Best if used with OSProcess 3.0

CommandShell is a Smalltalk simulation of a Unix command shell, with a
simple dumb terminal window in Morphic and MVC. It is useful for running
programs without leaving Squeak, and for piping command output directly
into Squeak.

CommandShell can be loaded and run on any platform, but is most useful
on Unix, Linux and Windows systems with OSProcess. Windows programs
can be launched from a 'Squeak Shell', although command pipelines with
external Windows programs are not yet possible. MacOS and other platforms
have not been tested.

When running on a Windows platform, CommandShell provides Unix style
command line parsing with DOS device names (C:, D:, etc) to mimic the
normal behavior of a DOS command shell. A set of builtin commands
('cd', 'pwd', 'sls' and 'edit') provide enough functionality to navigate
Windows file systems, list directory contents, and edit files.

On Windows, DOS style device names (such as 'C:') are recognized as part
of the path syntax, and separate current working directory paths are
maintained for each DOS style device. The command '$ cd D:' is interpreted
to mean 'change to the D: device and use its previous working directory
path'. When running on Unix, a single current working directory path is
maintained in the usual manner.

CommandShell provides a simple script processing capability. The
scripting methods are contained in the 'command scripting' category of
class CommandShell.

A script is a String containing a list of zero or more commands delimited
by Character cr. Each command in the list is treated as as a CommandShell
command line. The script commands may consist of a mix of Smalltalk
expressions, shell builtins, and external commands. Simple conditional
branching is supported for commands or scripts based on testing the exit
status of the command lines or scripts.

Try evaluating these expressions:
	CommandShell command: 'help'
	CommandShell open
	CommandShell new command: 'ps -aef | edit'
	CommandShell command: 'ps -aef | edit'
	CommandShell new command: 'ps -aef | edit'
	CommandShell command: 'edit /etc/hosts'
	CommandShell command: 'edit /etc/hosts; exit'
	CommandShell command: 'help | edit'
	CommandShell command: 'ps -aef | edit'
	CommandShell command: 'Time dateAndTimeNow!! | edit; exit'
	CommandShell command: 'Class allSubInstances!! | edit; exit'
	CommandShell command: 'type type | inspect; exit'

Class CommandShell is a command shell, similar to /bin/sh, with a command
line user interface. It collaborates with process proxies to provide command
execution, and provides a limited set of built in commands similar to those in
a Unix shell. Built in commands are implemented in Smalltalk. Simple
Smalltalk expressions, followed by $!!, are evaluated as doIt commands.
All other commands are passed to process proxies to be executed externally.

CommandShell can open a terminal window in either Morphic or MVC.

UnixCommandSyntax implements command line parsing and file name
globbing. This allows direct execution of external commands without use
of an external command shell.

PipeJunction represents an OS process or internal Smalltalk evaluator
connected in a command pipeline. PipeableOSProcess is a subclass which
collaborates with instances of ExternalOSProcess, and PipeableEvaluator
is a subclass to represent Smalltalk evaluation in a command pipeline.

PipeableEvaluator evaluates Smalltalk expressions and provides a framework
for pipelines of expressions combining Smalltalk expressions with external
Unix commands. It behaves similarly to a ConnectedUnixProcess. Both the
shell builtin commands and doIt expression commands are implemented with
PipeableEvaluator.

ShellBuiltin contains the implementations for shell builtin commands.
Instances of ShellBuiltin represent various commands, and may be installed
into an instance of CommandShell with CommandShell>>installCommand:.

CrLfFileEditor is a simple editor which can be used within command pipelines.
The 'edit' shell builtin creates an instance of CrLfFileEditor.

Changes in CommandShell 3.0 since CommandShell 1.6:
- Version number bumped to 3.0 for consistency with OSProcess. The major
  version bump is due to the addition of Windows support in OSProcess.
- Refactored to support OSProcess 3.0. Most importantly, added PipeJunction
  hierarchy with collaboration with ExternalOSProcess instances (replacing
  subclasses of platform specific OS process classes).

Changes in CommandShell 1.6 since CommandShell 1.5:
- Added limited support for Win32 to CommandShell, with correct file and
  path expansion.

- Added new 'sls' internal command to provide a simple directory listing.
- Add support for multiple working directories (one per device) for Windows.
- Renamed UnixCommandSyntax as ShellSyntax, and gave it responsibility
  for maintaining current working directories.
- Isolated platform specific methods in a 'platform specific' method category.
- Added scripting capability for the Squeak shell (see 'command scripting'
  category of class CommandShell).
- Fixed bug in ShellSyntax>>programNameAndArgumentsFrom:inDirectoryPath:
  in which a fully specified path was incorrectly evaluated.
- Added class ShellBuiltin, and moved all built in commands from
  CommandShell to the separate ShellBuiltin class.
- Added CommandShell class>>versionString.

Changes in CommandShell 1.5 since CommandShell 1.4:
- Added some more documentation (CommandShell class>>overview).
- Added direct Smalltalk evaluation to command line processing. Each
  command line is first evaluated as a Smalltalk, with no interpretation
  of shell characters such as $| prior to the evaluation. If this evaluation
  fails (either in the Compiler or at runtime), the command line is assumed
  to be a command pipeline and is subject to shell syntax interpretation
  (including doIt expressions, which may themselves be simple Smalltalk
  expressions). This turns out to work surprisingly well, with very little
  conflict with expected Unix style command interpretation. 
- Fixed various problems with error pipeline handling, and added SUnit
  tests to verify.
- Fixed a problem which allowed some pipeline data to be lost when
  piping very large strings to an editor or an inspector.
- Consolidated some code into #copyAllFrom:to: and improved performance
  for internal pipelines using this method.
- Fixed a bug in output and error redirection from the last process in
  a pipeline, where the last process is an internal command. For
  example, '$ who | copyToOutput > b' generated an error. Added SUnit
  tests to catch this condition.

Changes in CommandShell 1.4 since CommandShell 1.3:
- Fixes a timing problem for CommandShell pipelines running in MVC.
  Symptom: A command line such as '$ ls | edit' or '$ ls | inspect' did
  not work in an MVC shell window (Morphic was OK). The editor
  or inspector window would open and display an empty string.
  Cause: In MVC, the 'edit' and 'inspect' builtin commands scheduled
  an editor or inspector window to be opened at a later time using
  #addDeferredUIMessage:, and then cheerfully went on to close the
  input pipe for the command prior to the deferred action being
  executed.
  Fix: in a command pipeline, input to the 'edit' and 'inspect'
  shell builtin commands is now read completely prior to scheduling
  the editor or inspector window and closing the input pipe.
- Fixes a harmless but unappealing buglet in which the last proxy in
  a command pipeline was sent the #value message twice.
- Adds better error pipeline handling for command windows. Prior to
  this change, a command which generated a large amount our error
  output would clog up the pipes and cause the command window to
  hang up. I ran into the problem when running running configure
  and make to build a VM with VMMaker.
- Use deferred UI events in Morphic to eliminate intermittent red screen
  of death on '$ edit someBigFile' command.
- Fixed search for executable path in UnixCommandSyntax to properly
  handle the curent directory '.' in the PATH list.
- Added a #startUp handler to eliminate leftover Smalltalk processes
  after an image restart. The problem arose when a CommandShell
  ran an external program in background mode with a Smalltalk
  process waiting for the external program to exit. After an
  image restart, there was no way to be notified when the external
  process exited, so the Smalltalk process was left dangling forever.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CommandShellV3-0-dtl.cs.gz
Type: application/x-gunzip
Size: 51542 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20020311/e588d651/CommandShellV3-0-dtl.cs.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CommandShell-menuV3-0-dtl.cs.gz
Type: application/x-gunzip
Size: 1092 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20020311/e588d651/CommandShell-menuV3-0-dtl.cs.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CommandShell-sUnitV3-0-dtl.cs.gz
Type: application/x-gunzip
Size: 5218 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20020311/e588d651/CommandShell-sUnitV3-0-dtl.cs.bin


More information about the Squeak-dev mailing list