External processes from Squeak

David T. Lewis lewis at mail.msen.com
Sun Jul 28 11:49:45 UTC 2002


On Sun, Jul 28, 2002 at 08:54:23AM +0200, Yoel Jacobsen wrote:
> 
>     Is there a way to execute an external process from squeak and get 
> its input, output and error streams? (something like popen() )

Assuming that you are using a Unix or Linux system, load the OSProcess
(http://minnow.cc.gatech.edu/squeak/708) and CommandShell
(http://minnow.cc.gatech.edu/squeak/1914) change sets.

To run an external process with access to input/output/error streams:
  | p |
  p _ PipeableOSProcess command: 'ls -l * NONESUCH'.
  p output inspect.
  p errorUpToEnd inspect.

or:
  | p |
  p _ PipeableOSProcess command: 'cat'.
  p nextPutAll: 'hello world!'.
  p close.
  p output inspect.

Note: PipeableOSProcess>>output will block on the pipe read, so be sure
to do the #close.  See PipeableOSProcess>>upToEnd for a nonblocking read.

If you have recently downloaded Ian's Unix VM, the required plugin
(UnixOSProcessPlugin.so) is already included, so just load the change
sets and all should be well. Otherwise, source code for the plugin is
included in the OSProcess change set.

Dave
 



More information about the Squeak-dev mailing list