[squeak-dev] Re: Processing a file at image startup (scripting)
andreas.raab at gmx.de
Wed May 20 15:37:06 UTC 2009
If you are shipping a "real" application (i.e., not some image that
people do further development in) it is probably advantageous to do the
command line handling yourself. This is extremely simple:
1) Execute "AutoStart deinstall" when you prepare your app to get
AutoStart and ProjectLauncher out of the way.
2) When your app starts, process command line args as you'd like, for
"Process command line arguments for this application"
| index attr arg forumToLoad robot |
self isSealedApplication ifFalse:[^nil]. "only process command line
for sealed apps"
index := 0.
[attr := Smalltalk getSystemAttribute: (index := index + 1).
attr isNil] whileFalse:[
['-enableDebug'] -> [
self enableDebug: true.
['-debugLevel:'] -> [
arg := (Smalltalk getSystemAttribute: (index := index +
self debugLevel: arg.
"Check if this is just a file that was associated with the app"
(self isKnownFileType: attr)
ifTrue:[self launchWithFile: attr].
Cédrick Béler wrote:
> While delivering a small app (a project scheduler), people asked me if
> it's possible to execute it by a command line without opening an
> image. I have a pseudo-dsl to define a project (collection of tasks)
> that the app is scheduling and so, what I'd like is launching the app
> by passing a file as parameter. Then squeak "open headless", process
> the entry file, write an outputfile with results and eventually
> errors, and exit.
> I did something but this is a terrible hack :) I'd like to have other
> idea on that. If we consider:
> squeak -headless test.image file.in
> According to the vm man, file.in must be a script (st file with bang
> notation). I'm not aware of a way to pass a plain text file. So I just
> hacked ProjectLauncher>>startUpAfterLogin (this is where I get a dnu
> if passing a file as parameter) so that my file can be processed and
> the image closed afterwhile.
> Can people point me a better way of doing that ? My feeling is I need
> to create a ScriptClass that has a startUp method where file
> processing can be implemented.
> ps: a related question would be which startUp classes are not
> necessary if we only need to process a File (do we need InputSensor,
More information about the Squeak-dev