About scripting...

David T. Lewis lewis at mail.msen.com
Mon Aug 15 10:45:53 UTC 2005


On Sun, Aug 14, 2005 at 10:19:07PM -0600, Brian Murphy-Dye wrote:
> So how would one get the results of:  'ls -l | grep -i Squeak'?
> CommandShell command: 'ls | grep -i Squeak'   brings up a new window  
> rather than returning the results of the command as a string :o[
> 
> Brian.
> 

Use the instance side methods to avoid opening the CommandShell
window. Try inspecting this:

    | pipeline |
    pipeline := CommandShell new pipeline: 'ls -l | grep -i Squeak'.
    (Delay forMilliseconds: 20) wait. "oops, this should not be necessary"
    pipeline last upToEnd

But it looks like there is a timing glitch that I need to iron out.
The expression:

    (CommandShell new command: 'ls -l | grep -i Squeak') upToEnd

is supposed to produce the output you expect. I think this is a bug
in CommandShell, presumably in the way I'm handling the closing of pipes
in a pipeline of external processes. It seems to show up in post-3.6
Squeak images, but I think it's a bug in my pipeline handling.

In any case, if you create the command pipeline as shown above, and
wait a few milliseconds before reading the output pipe, you will get
the result you're looking for.

If you are interested in doing command scripts using external commands
mixed with Squeak, have a look at the methods in "command scripting"
in class CommandShell. I've used these for things like building Squeak
plugins and restarting Squeak only if the external commands succeed.

You can use these with or without the shell window being open. It's
nice to open the window if you are building a VM, but you can leave
it closed if you just want to run a command script silently.

Dave


> On Aug 14, 2005, at 12:00 PM, David T. Lewis wrote:
> 
> > On Sun, Aug 14, 2005 at 06:06:44PM +0200, stephane ducasse wrote:
> >
> >>>
> >>>
> >>> Yes, but from the limited time I spent looking into it, it not so
> >>> easy to execute  a program from squeak though. I got as far as
> >>> loading the OSProcessPlugin before talk of using VMMaker got me
> >>> thoroughly confused. Is there a simple guide on how to execute a
> >>> shell command from Squeak that does not require me to compile a VM?
> >>>
> >>> Daniel
> >>>
> >
> > If you are using a Unix VM (one of the pre-compiled VMs from Ian's  
> > site),
> > then the plugins (OSProcessPlugin and XDisplayControlPlugin) are  
> > already
> > included. You don't have to build anything. Just load the OSProcess  
> > and
> > CommandShell packages from Squeak Map and everything should work fine.
> >
> > Dave




More information about the Squeak-dev mailing list